设置 QComboBox的下拉框Item高度

来源:互联网 发布:淘宝排名查询网站 编辑:程序博客网 时间:2024/05/29 10:51
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文件就可以完成设置下拉框宽度的工作,而不需要再加入额外的代码了。

1 1
原创粉丝点击