【发布时间】:2011-03-10 06:29:38
【问题描述】:
我有一个QComboBox,我用QString 填写:
comboBox->addItem(someString);
当我启动我的 GUI 应用程序时,QComboBox 的宽度始终为 70,即使最小的项目要大得多。例如,如何将QComboBox 的宽度动态设置为comboBox 中最大的QString?
编辑:
经过进一步测试,我找到了以下解决方案:
// get the minimum width that fits the largest item.
int width = ui->sieveSizeComboBox->minimumSizeHint().width();
// set the ComboBoxe to that width.
ui->sieveSizeComboBox->setMinimumWidth(width);
【问题讨论】:
-
另外,如果你想保持组合框大小不变,但扩大下拉宽度以适应最长的字符串,你可以设置视图的最小宽度:
ui->sieveSizeComboBox->view()->setMinimumWidth(width); -
感谢您的评论,正是我所需要的。
标签: c++ user-interface qt qcombobox