设置 QComboBox的下拉框Item高度

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文件就可以完成设置下拉框宽度的工作,而不需要再加入额外的代码了。

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值