c++ - Qt 样式表中的属性组合

标签 c++ qt qtstylesheets

我编写了 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/

相关文章:

python - 如何调整 QInputDialog、PyQt 的大小

c++ - Tor 控件去哪儿了?

Qt 样式表,来自文件路径的背景图像

c++ - 将 vector 结构传递给函数

c++ - 如何在 C/C++ 中默认初始化函数指针?

python - QListView 不接受使用 Python PyQt4 的 QMainWindow 中的放置

c++ - QTableView 的边框和文本 qss 设置

c++ - 从 "fusion"样式的 QTreeView 中删除蓝色选择

c++ - Visual Leak Detector 检测新空白 MFC 项目的泄漏

c++ - 正确访问 const 一行特征矩阵