c++ - 我可以从样式表 (qss) 更改自定义动态属性吗?

标签 c++ qt qtstylesheets qframe

我有一个像这样的自定义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 the qproperty-<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/

相关文章:

c++ - 禁用模板类中的函数

c++ - wxtooltip wxwidgets

c++ - 如何从 C++ 代码访问 .qrc 文件中指定的文件?

qt - 使用样式表定义选项卡背景而不更改 QWidget?

qt - QListView 放置指示器样式

c++ - 在 C 程序中使用单个 C++ 类的最佳方式

c++ - 使用 WinCrypt/CryptoAPI 验证基于 OpenPGP 的 RSA 签名

c++ - 使用 Qt 在 C++ 中委派类构造函数

qt - iOS 和 Android 中的照片库

c++ - Qt标签中的QLabel边距和样式表填充