如何使用QSS为禁用按钮设置不同的背景颜色

How to set a different background-color to a disabled button with QSS?

本文关键字:背景 颜色 设置 按钮 QSS 何使用      更新时间:2023-10-16

我已经尝试使用disabled!enabled,但它不起作用。这是我的QSS代码:

QPushButton {
    background-color:#44c767;
    border-radius:5px;
    border:1px solid #18ab29;
    color:#ffffff;
    font-family:arial;
    font-size:15px;
    font-weight:bold;
    text-decoration:none;
    padding-right:10px;
    outline: 0;
}
QPushButton:hover:!pressed {
    background-color:#54d777;
}
QPushButton: pressed {
    background-color:#30b252;
}
QPushButton: disabled {
    background-color:#ff0000;
}
QPushButton: !enabled {
    background-color:#ff0000;
}

文档提到了一个disabled伪状态,但没有提供更多的信息。

编辑

我使用的是QT5.3

删除冒号后的所有空格(实际上是全部-因为它使进一步的css文本无效),它将工作:

QPushButton:disabled {
background-color:#ff0000;
}

实际上,disabled!enabled都可以。