本文介绍了扁平QPushButton,背景色不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下样式表在Qt Designer中创建了QPushButton:

I created QPushButton in Qt Designer with this stylesheet:

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,我该怎么办?

It Works, but when i check "flat" in the properties, then it doesn't work anymore, I would like to ask you why? And how can i do it, if i need flat QPushButton ?

推荐答案

对于问题的第二部分:不要使用"flat"属性,而是修改样式表以实现平坦外观,也许像这样:

For the second part of your question: Don't use the "flat" property, but modify your stylesheet to achieve a flat look, perhaps like this:

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

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

Concerning the "why doesn't it work" part? In my experience, mixing stylesheets and non-stylesheet-options for widgets yields many mysterious effects that are hard to explain. I have given up asking for the "why"s.

这篇关于扁平QPushButton,背景色不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 02:10