Reputation: 1022
In my custom designer widget plugin I have a custom widget that derives QProgressBar. I have a field to chose either a determinate or indeterminate state. For this I have simply made an enum with the two states. I would like to use these values in the QtDesigner widget property area via implementing a Q_PROPERTY macro as follows:
class QDESIGNER_WIDGET_EXPORT QtMaterialProgress : public QProgressBar
{
Q_OBJECT
Q_PROPERTY(QColor progressColor WRITE setProgressColor READ progressColor)
Q_PROPERTY(QColor backgroundColor WRITE setProgressColor READ backgroundColor)
Q_PROPERTY(Material::ProgressType progressType WRITE setProgressType READ progressType)
.....
And also here is the enum declaration:
enum ProgressType
{
DeterminateProgress,
IndeterminateProgress
};
I would expect this piece of code to produce a QComboBox in the property editor of QtDesigner with the two states, however I get non of the such. I have also tried adding Q_ENUMS(PropertyType)
to the header with no luck.
Upvotes: 1
Views: 1008
Reputation: 243955
You have to use Q_ENUM
(Not Q_ENUMS
since it is deprecated from Qt 5.5: https://doc.qt.io/qt-5/whatsnew55.html) as the following example shows:
#ifndef TESTWIDGET_H
#define TESTWIDGET_H
#include <QWidget>
class TestWidget : public QWidget
{
Q_OBJECT
Q_PROPERTY(EnumTest test READ test WRITE setTest)
public:
TestWidget(QWidget *parent = 0);
enum EnumTest { ENUM0, ENUM1, ENUM2, ENUM3 };
Q_ENUM(EnumTest)
EnumTest test() const;
void setTest(const EnumTest &test);
private:
EnumTest mTest;
};
#endif
In the following link you can find a complete example
Upvotes: 2