How to use flags as custom widget property type in QT?
Unsolved
General and Desktop
-
I have trouble to use flags as QT custom widget property type. The expected property does not show on QT Designer property editor.
The code is as below:
#ifndef SVBASICDEMO_H #define SVBASICDEMO_H #include <QString> #include <QtUiPlugin/QDesignerExportWidget> #include <QWidget> #include <QLabel> #include "svbasicwidget.h" QT_BEGIN_NAMESPACE namespace Company { namespace Product { namespace Widget { namespace Basic { class QDESIGNER_WIDGET_EXPORT SvBasicDemo : public SvBasicWidget { Q_OBJECT Q_FLAGS(SvBasicDemo::AccessTypes) Q_PROPERTY(QString url_prop MEMBER url_prop NOTIFY propertyChange) Q_PROPERTY(Priority enum_prop MEMBER enum_prop NOTIFY propertyChange) Q_PROPERTY(AccessTypes flag_prop MEMBER flag_prop NOTIFY propertyChange) Q_PROPERTY(Qt::Alignment flag_prop_2 MEMBER flag_prop_2 NOTIFY propertyChange) Q_SIGNALS: void propertyChange(); public slots: //更新属性的槽 void updateProperty(); public: SvBasicDemo(QWidget *parent = 0); virtual void refresh_binding_cb(); virtual QString help_info() const; enum Priority { High, Low, VeryHigh, VeryLow }; Q_ENUM(Priority) enum AccessType { Read = 0x1, Write = 0x2 }; Q_DECLARE_FLAGS(AccessTypes, AccessType) private: QString url_prop; Priority enum_prop; AccessTypes flag_prop; Qt::Alignment flag_prop_2; QLabel label; }; Q_DECLARE_OPERATORS_FOR_FLAGS(SvBasicDemo::AccessTypes) } } } } QT_END_NAMESPACE #endif
The result in qt designer property editor is shown as below: enter image description here
You can see property enum_prop (use custom enum) and flag_prop_2 (use built in flag Qt::Alignment) works as expected. But property flag_prop is missing.I have study the code in "%QT_ROOT%\Qt5.6.0\5.6\msvc2013\include\QtWidgets\qgraphicsview.h"。 And did not figure out why.
Could anyone give me some hint about why it does not work as expected? Thanks in advance.