QCombobox 设置item的高度 样式表

来源:互联网 发布:数控车螺纹编程实例 编辑:程序博客网 时间:2024/05/22 15:52
Qt Code:
Switch view
  1. setStyleSheet("QComboBox { min-height: 40px; min-width: 60px; }"
  2. "QComboBox QAbstractItemView::item { min-height: 40px; min-width: 60px; }");
  3. QComboBox *combo = new QComboBox(this);
  4. combo->setView(new QListView());
To copy to clipboard, switch view to plain text mode 
if you omit the last line (setView call), the style sheet wont be applied to the default combobox item view. 

我的UI是在QtCreator中设计的,为了避免为每个QComboBox控件都写上combo->setView(new QListView()), 我的派生了自己的QComboBox类,并在他的构造函数中加入了 setView(new QListView()),并把所有的QComboBox都提升为自己的QComboBox类。这样,我只需要 通过Qss文件和ui文件就可以完成设置下拉框宽度的工作,而不需要再加入额外的代码了。
0 0
原创粉丝点击