【问题标题】:Flat QPushButton, background-color doesn't workFlat QPushButton,背景颜色不起作用
【发布时间】:2016-04-11 19:23:07
【问题描述】:

我用这个样式表在 Qt Designer 中创建了QPushButton

QPushButton#pushButton { 
    background-color: #ffffff;
}
QPushButton#pushButton:disabled {
    background-color: yellow; 
}
QPushButton#pushButton:pressed {
    background-color: orange; 
}
QPushButton#pushButton:focus:pressed { 
    background-color: black;
 }
QPushButton#pushButton:focus { 
    background-color: green; 
}
QPushButton#pushButton:hover {
     background-color: red;
 }
QPushButton#pushButton:checked { 
    background-color: pink;
 }

它可以工作,但是当我在属性中选中“flat”时,它就不再工作了,我想问你为什么?如果我需要平坦的QPushButton,我该怎么做?

【问题讨论】:

  • 上面这个非常非常非常非常有用!感谢分享
  • @KGCybeX 欢迎您:)

标签: qt qtstylesheets qpushbutton flat


【解决方案1】:

对于您问题的第二部分:不要使用“flat”属性,而是修改您的样式表以实现扁平外观,可能是这样的:

QPushButton#pushButton { 
    background-color: #ffffff;
    border: 0px;
}
/* ... plus the rest of your stylesheet ... */

关于“为什么它不起作用”部分?以我的经验,混合样式表和非样式表选项的小部件会产生许多难以解释的神秘效果。我已经放弃问“为什么”了。

【讨论】:

    猜你喜欢
    • 2014-01-07
    • 2014-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-25
    • 2016-06-11
    • 2012-02-20
    • 2012-07-11
    相关资源
    最近更新 更多