我编写了 Qt4(或 Qt5)类 MyButton 并定义了两个 bool 属性,如下所示:
#include <QPushButton>
class MyButton : QPushButton
{
Q_OBJECT
Q_PROPERTY(bool property_1 READ property_1)
Q_PROPERTY(bool property_2 READ property_2)
public:
explicit MyButton(QWidget *parent = 0);
...
}
现在我想在外部文件中自定义应用程序样式表,以便在该属性的不同组合中 MyButton 具有不同的背景颜色。分开来看效果很好:
MyButton[property_1="true"] { background-color: black }
MyButton[property_2="true"] { background-color: white }
那么问题来了:如何通过“与”、“或”、“非”运算将同一条件下的几个属性组合起来?
最佳答案
我终于找到了解决方案。思路同CSS attribute selection .
因此 property_1="true"AND property_2="true"条件为:
MyButton[property_1="true"][property_2="true"] { background-color: green; }
关于c++ - Qt 样式表中的属性组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24631667/