【问题标题】:Not able to hide Choice-Indicator of the QComboBox无法隐藏 QComboBox 的选择指标
【发布时间】:2012-07-21 12:00:27
【问题描述】:
程序员
当我设置属于 QComboBox(每个 QSS)的列表视图的背景颜色时,这个 QComboBox 将不再使用内置的光学外观。我还必须根据 QSS 样式表指定所有光学设置:
QComboBox QListView {
background-color:white;
border:1px solid black;
}
显示可选择项的列表视图现在在左侧显示一个复选框。选中此框以查看上次使用时选择的那些项目。
如何隐藏带有复选框的列,使它们不可见并且不会占用屏幕上的任何空间?
提前谢谢...
【问题讨论】:
标签:
checkbox
stylesheet
indicator
qcombobox
qtstylesheets
【解决方案1】:
QComboBox 难以绘制主题的 QSS 解决方法
如果您不使用 QSS 块,则 QComboBox 将使用其 OS-Look-and-Feel 进行绘制。如果您开始指定 QSS 规则,则 QComboBox 的某些或所有子控件开始失去 OS-Look-and-Feel。在最坏的情况下,您现在必须在 QSS 中指定所有属性。
本文的主题是选择指示器,由 QStyleViewItem 类绘制,它是 QT 源代码中 .../src/gui/widgets/qcombobox_p.h 中实现的渲染助手。此功能似乎无法通过 QProxyStyle 的子类进行修改,该子类可在其他情况下用于解决硬布局问题。
但是,我通过指定一组精心挑选的规则在 QSS 中找到了解决方案:
/* 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;
}