我有一个像这样的自定义QFrame
//! Widget which displays a audio level meter, indicating the
//! level and peak levels of the window of audio samples most recently analyzed
class BLACKGUI_EXPORT CLevelMeter : public QFrame
{
Q_OBJECT
Q_PROPERTY(QColor lowColor READ getLowColor WRITE setLowColor)
Q_PROPERTY(QColor highColor READ getHighColor WRITE setHighColor)
Q_PROPERTY(QColor peakColor READ getPeakColor WRITE setPeakColor)
我想在 qss
样式表中设置这些颜色,如下所示
BlackGui--CLevelMeter {
lowColor: blue;
border: 1px solid grey;
border-radius: 5px;
这不起作用,有机会这样做吗?
最佳答案
如the docs指出:
Setting QObject Properties
From 4.3 and above, any designable Q_PROPERTY can be set using theqproperty-<property name>
syntax.For example,
MyLabel { qproperty-pixmap: url(pixmap.png); } MyGroupBox { qproperty-titleColor: rgb(100, 200, 100); } QPushButton { qproperty-iconSize: 20px 20px; }
If the property references an enum declared with Q_ENUMS, you should reference its constants by name, i.e., not their numeric value.
您必须使用qproperty-lowColor
.
关于c++ - 我可以从样式表 (qss) 更改自定义动态属性吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58126182/