Qt Code:
Switch view
-
setStyleSheet( "QComboBox { min-height: 40px; min-width: 60px; }"
-
"QComboBox QAbstractItemView::item { min-height: 40px; min-width: 60px; }");
-
combo->setView( new QListView());
To copy to clipboard, switch view to plain text mode
我的UI是在QtCreator中设计的,为了避免为每个QComboBox控件都写上combo->setView(new QListView()), 我的派生了自己的QComboBox类,并在他的构造函数中加入了 setView(new QListView()),并把所有的QComboBox都提升为自己的QComboBox类。这样,我只需要 通过Qss文件和ui文件就可以完成设置下拉框宽度的工作,而不需要再加入额外的代码了。