【问题标题】:QComboBox Selected Item background is not reflectedQComboBox 所选项目背景未反映
【发布时间】:2013-07-18 07:08:34
【问题描述】:

我想通过样式表设置 QComboBox 的样式,所以我应用了以下 qss 语法。

 QComboBox {
    border: none;
    border-radius: 0px;
background-color: rgb(255, 255, 255);
color: rgb(0, 0, 0);
selection-background-color: rgb(0, 85, 255);
font: 14pt;
 }

 QComboBox:editable {
     background-color: rgb(255, 255, 255);
 }

QComboBox:!editable:on, QComboBox::drop-down:editable:on {
     background-color: rgb(200, 200, 200);
 }

 QComboBox:on { /* shift the text when the popup opens */
     padding-top: 3px;
     padding-left: 4px;
 }

QComboBox::drop-down {
width: 0px;
height:0px;
border-radius: 0px;
}

QComboBox::drop-down:hover
{
    border: none;
    border-radius: 0px;
background-color: rgb(0, 170, 255);
}   

QComboBox QAbstractItemView{
background-color: rgb(255, 255, 255);
    border-radius: 0px;
color: rgb(0, 0, 0);
font: 14pt;
 }

QComboBox QAbstractItemView:item{
color: rgb(85, 85, 0);
background-color: rgb(170, 170, 127);
selection-background-color: rgb(170, 170, 255);
selection-color: rgb(85, 0, 127);
height:40px;
font: 16pt;
 }

问题: selection-background-color: rgb(170, 170, 255);在

     QComboBox QAbstractItemView:item{
color: rgb(85, 85, 0);
background-color: rgb(170, 170, 127);
selection-background-color: rgb(170, 170, 255); <- Not Working
selection-color: rgb(85, 0, 127);
height:40px;
font: 16pt;
 }

没有申请。下拉所选项目背景不反映。 请帮我解决这个问题。

【问题讨论】:

    标签: qt


    【解决方案1】:

    你试过了吗:

    QComboBox QAbstractItemView
    {
    background-color: rgb(255, 255, 255);
    selection-background-color: rgb(170, 170, 255); <- Should Now Work
    border-radius: 0px;
    color: rgb(0, 0, 0);
    font: 14pt;
    }
    

    【讨论】:

    • @Jacob.. 哈哈哈,但不幸的是现在我要在下个月开始重新进入 Qt
    【解决方案2】:

    我刚刚遇到了同样的问题,对我来说,我在互联网上找到的所有建议的解决方案都不起作用。最后是这样的:

    QComboBox::item:selected
    {
        background-color: rgb(170, 170, 255);
        color: rgb(0, 0, 0);
    }
    

    希望这可以帮助其他用户搜索此内容。 也许这在最近的版本中有所改变(我使用的是 Qt 5.7)。

    【讨论】:

      【解决方案3】:

      我遇到了这个问题。每次选择组合框(GUI 中的焦点项目)时,该框都是蓝色的,带有白色文本。我最初尝试添加:

      QComboBox QAbstractItemView {
      selection-background-color: white;
      }
      

      但是,这不起作用。

      经过一番调查,我意识到“selection-background-color”标签是正确的,但它不在正确的对象上。标记“QComboBox QAbstractView”将更改下拉视图,但不会更改 QComboBox 本身。为此,您必须将标签附加到 QComboBox(不限于仅 ComboBox 的 QAbstractItemView)。这就是我将我的从蓝色更改为白色的方式(选中时):

      QComboBox {
      selection-background-color: white;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-08-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多