qcombobox 隐藏,无法隐藏QComboBox的选择指示器

programmer

When I set the background-color of the list view belonging to the QComboBox (per QSS), then this QComboBox will no more use the built-in-opticel-look-and feel. Instaed I have to specify all optical settings also per QSS-Stylesheet:

QComboBox QListView {

background-color:white;

border:1px solid black;

}

The list view, which shows the chosable item, displays a checkbox on the left now. This box is checked for those item, chosen on last usage.

How can i hide the column with the checkboxes, so that they will be unvisible and will not be consume any space on the screen?

Thanks in advance...

解决方案

QSS Workaround for a difficult draw topic of QComboBox

If you don't use a QSS block, the QComboBox is drawn with its OS-Look-and-Feel. If you are starting to specify QSS rules some or all subcontrols of the QComboBox begin to lose the OS-Look-and-Feel. In worst case you have to specify all properties in QSS now.

Subject of this article is the choice indicator, drawn by the QStyleViewItem class, a render helper implemented in .../src/gui/widgets/qcombobox_p.h within the QT sources. This functionality seems to be unpossible modifyable by a subclass of QProxyStyle which can be used in other cases for hard layout problems.

However, I found a solution in QSS by specifying a well chosen set of rules:

/* Background color of popup-list.*/

QComboBox QListView{

background-color:white;

border:1px solid gray;

}

/* Needed to complete the rule set. */

QComboBox::item:alternate {

background: white;

}

/* Color of the selected list item. */

QComboBox::item:selected {

border: 1px solid transparent;

background:yellow;

}

/* Indicator will shine through the label text if you don't make it hidden. */

QComboBox::indicator{

background-color:transparent;

selection-background-color:transparent;

color:transparent;

selection-color:transparent;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值