How to use flags as custom widget property type in QT?

  • 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"
    namespace Company {
    namespace Product {
    namespace Widget {
    namespace Basic {
    class QDESIGNER_WIDGET_EXPORT SvBasicDemo : public SvBasicWidget
            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)
        void propertyChange();
        public slots:
        void updateProperty();
        SvBasicDemo(QWidget *parent = 0);
        virtual void refresh_binding_cb();
        virtual QString help_info() const;
        enum Priority { High, Low, VeryHigh, VeryLow };
        enum AccessType { Read = 0x1, Write = 0x2 };
        Q_DECLARE_FLAGS(AccessTypes, AccessType)
        QString url_prop;
        Priority enum_prop;
        AccessTypes flag_prop;
        Qt::Alignment flag_prop_2;
        QLabel label;

    The result in qt designer property editor is shown as below: enter image description here
    alt text
    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.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.