c++qtqt-creatorqproperty

How to get Q_PROPERTYs to show in Design Viiew


I have a class derived from QPushButton with Q_PROPERTYs but they do not appear in the Property Editor of Design Mode.

There is a QPushButton promoted to my custom class in the design view and I would expect the properties to automatically display in the Property Editor, at least the one with type "int". There is a good chance I am misunderstanding something simple.

Here is what looks like the relevant lines in the code:

class virtualButton : public QPushButton
{
    Q_OBJECT

    Q_PROPERTY(int number MEMBER m_number DESIGNABLE true USER true STORED true CONSTANT)
    Q_PROPERTY(buttons::keySet set MEMBER m_set DESIGNABLE true USER true STORED true CONSTANT)
...

The code compiles fine.


Solution

  • Did you make a Qt plugin from your widget?

    If it is only code and you use it via "propagate to" in Qt Designer, that won't make the trick, only providing a plugin works. Read more here and in similar articles in official documentation.

    In short -- you can provide Designer with libraries, made using Qt plugin framework, that would contain your widgets. Of course, if you consider it worth the effort.