无法隐藏QComboBox的选择指示器 [英] Not able to hide Choice-Indicator of the QComboBox

查看:148
本文介绍了无法隐藏QComboBox的选择指示器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

程序员

当我设置属于 QComboBox 的列表视图的背景颜色(根据QSS)时,此QComboBox将不再使用内置的外观和感觉。我必须同时根据QSS样式表指定所有光学设置:

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.

我如何隐藏带有复选框的列,以使它们不可见且不会会消耗屏幕上的任何空间吗?

预先感谢...

推荐答案

QComboBox的困难抽奖主题的QSS解决方法

如果您不使用QSS块,则QComboBox是使用其OS外观和感觉绘制的。如果您开始指定QSS规则,则QComboBox的某些或所有子控件将开始丢失OS外观。在最坏的情况下,您必须立即在QSS中指定所有属性。

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.

本文的主题是选择指示符,由QStyleViewItem类绘制,该实现是在.Style中实现的。 QT源中的./src/gui/widgets/qcombobox_p.h。此功能似乎无法通过QProxyStyle的子类进行修改,该子类可在其他情况下用于解决硬布局问题。

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.

但是,我在QSS中找到了一个解决方案,方法是指定一个精选的规则集:

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;
}

这篇关于无法隐藏QComboBox的选择指示器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆