如何使用 QSS 为禁用的按钮设置不同的背景颜色? [英] How to set a different background-color to a disabled button with QSS?

查看:129
本文介绍了如何使用 QSS 为禁用的按钮设置不同的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have already tried to use disabled and !enabled but it doesn't work. Here is my QSS code :

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 伪状态,但没有提供有关它的更多信息.

The documentation refers to a disabled pseudo state but without providing more information about it.

编辑

我使用的是 QT5.3

I am using QT5.3

推荐答案

删除冒号后的所有空格(真的全部 - 因为它使进一步的 css 文本无效)并且它会起作用:

Remove all spaces after colons (really ALL - because it invalidates the further css text) and it will work:

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

实际上,disabled!enabled 都有效.

Actually, both disabled and !enabled works.

这篇关于如何使用 QSS 为禁用的按钮设置不同的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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