Unsolved Creating custom Widgets with struct/class property for use in QtDesigner
-
Hello
After lots of trail and error i managed to create custom widgets with properties of primitive or Qt buildin types. However, i can't find any information on how to create a property of a struct or class type.
The members or that struct/class itself are primitive or Qt types again.What i want is just the ability to expand the property node in Qt form designer and edit the members separately.
Similar to how i can edit the color channels of a QColor typed property or the height and width of a QSize typed property.I tried to create a property class like this:
#include <QObject> class CustomPropertyClass { Q_GADGET Q_PROPERTY(int someValue READ someValue WRITE setSomeValue) public: CustomPropertyClass(); CustomPropertyCass(const CustomPropertyClass& s); ~CustomPropertyClass() {} int someValue () const {return m_some_value;} void setSomeValue(int some_value) {m_some_value = some_value;} protected: int m_some_value; } Q_DECLARE_METATYPE(CustomPropertyClass)
And then adding it to the widget class:
#include "custompropertyclass.h" class MyWidget: public QWidget { Q_OBJECT Q_PROPERTY(CustomPropertyClass foo READ foo WRITE setFoo) public: CustomPropertyClass foo() const {return m_foo;} void setFoo(const CustomPropertyClass &foo){m_foo = foo;} protected: CustomPropertyClass foo; }
But QtCreator will not show the property. It prints out
The property "foo" of type (unknown) is not supported yet!What am i missing? Is there any working example?
Using Qt 5.9.2, QtCreator 4.4.1