Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Display comboBox like list with Q_PROPERTY

Display comboBox like list with Q_PROPERTY

Scheduled Pinned Locked Moved General and Desktop
18 Posts 4 Posters 8.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    neel2818
    wrote on last edited by
    #1

    Hi All,

    I have used the Q_PROPERTY to set the different property through Qt designer. I have used the following Q_PROPERTY.

    Q_PROPERTY(QString objectName READ getObjectName WRITE setObjectName)

    But i want to display combobox like list of string with Q_PROPERTY. sa how can we acieve this ?

    Thanks,
    Neel

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      Please rephrase your question, it is not clear what you are after.

      You can store anything you want (well, anything that you can fit in a QVariant) in properties in QObjects, but they won't automagically result in UI elements like combo boxes.

      1 Reply Last reply
      0
      • N Offline
        N Offline
        neel2818
        wrote on last edited by
        #3

        I mean to say that QWidget has property layoutDirection. If you see this property through Qt designer then when you set LefttoRight or RighttoLeft through designer then you will see the comboBox that will allow user to set the value.

        So i want similar behaviour in my custom widget. Can you please tell ?

        Thanks,
        Neel

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          Ah, so you want a property editor?

          The one used in Qt Designer itself is available to you, but there are also 3rd party options. I have personally used YAPE (Yet Another Property Editor) that is available as a download from qt-app.org in the widgets section. There are others there as well.

          1 Reply Last reply
          0
          • N Offline
            N Offline
            neel2818
            wrote on last edited by
            #5

            Hi Andre,

            Just for your information i have done it without use of property editor. As i want ti display comboBox in property editor of my custom widget. Following is the syntax of Q_PROPERTY to display like combobox in property editor in Qt designer.

            Q_PROPERTY(CustomWidget::ParamTypeList ParamType READ getParamType WRITE setParamType)

            1 Reply Last reply
            0
            • S Offline
              S Offline
              shootstar
              wrote on last edited by
              #6

              Hi Neel,
              i need to develop some activex controls with qt. Then , i want to display comboBox in property editor of my custom widget, just like you. But i haven't find method , can you help me ? i see you said like "Q_PROPERTY(CustomWidget::ParamTypeList ParamType READ getParamType WRITE setParamType)" , but what's the type of CustomWidget::ParamTypeList ? and how to define getParamType(or set) function?

              thanks,
              shootstar

              1 Reply Last reply
              0
              • raven-worxR Offline
                raven-worxR Offline
                raven-worx
                Moderators
                wrote on last edited by
                #7

                i guess the property editor creates a combo box if the property is an enum type.

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  shootstar
                  wrote on last edited by
                  #8

                  hi raven-worx, thank you for your replay!
                  i have use an enum type ,like "enum ParamTypeList{...}", but it also not solve my problem, and if the property defined as enum, it will not be displayed in the property page.

                  thanks,
                  shootstar

                  1 Reply Last reply
                  0
                  • raven-worxR Offline
                    raven-worxR Offline
                    raven-worx
                    Moderators
                    wrote on last edited by
                    #9

                    [quote author="shootstar" date="1370589776"]hi raven-worx, thank you for your replay!
                    i have use an enum type ,like "enum ParamTypeList{...}", but it also not solve my problem, and if the property defined as enum, it will not be displayed in the property page.
                    [/quote]
                    i think you also have to specify the "Q_ENUMS macro":http://qt-project.org/doc/qt-4.8/qobject.html#Q_ENUMS in your class definition so Qt knows about it

                    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                    If you have a question please use the forum so others can benefit from the solution in the future

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      shootstar
                      wrote on last edited by
                      #10

                      well, i specify the Q_ENUMS macro, like "Q_ENUMS(ParamTypeList)",and it has passes the compiler and linker. But the property does't display in the property in the property page still.

                      1 Reply Last reply
                      0
                      • raven-worxR Offline
                        raven-worxR Offline
                        raven-worx
                        Moderators
                        wrote on last edited by
                        #11

                        just to make sure: you subclass QObject (or a class which inherits QObject) and you have Q_OBJECT macro specified?

                        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                        If you have a question please use the forum so others can benefit from the solution in the future

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          shootstar
                          wrote on last edited by
                          #12

                          my .h file just like this:
                          class AxisCoord : public QWidget, public QAxBindable
                          {
                          Q_OBJECT
                          Q_ENUMS(ParamTypeList)
                          Q_PROPERTY( QString nctype READ GetType WRITE SetType)
                          Q_PROPERTY( int value READ value WRITE setValue )
                          Q_PROPERTY(ParamTypeList ParamType READ getParamType WRITE setParamType)

                          public:
                          AxisCoord(QWidget *parent = 0);

                          QString GetType() const;
                          int value() const;
                          enum ParamTypeList
                          {
                          TYPE1,
                          TYPE2,
                          TYPE3
                          };

                          ParamTypeList getParamType() const;
                          ... //other code
                          }

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            shootstar
                            wrote on last edited by
                            #13

                            my .h file just like this:
                            @class AxisCoord : public QWidget, public QAxBindable
                            {
                            Q_OBJECT
                            Q_ENUMS(ParamTypeList)
                            Q_PROPERTY( QString nctype READ GetType WRITE SetType)
                            Q_PROPERTY( int value READ value WRITE setValue )
                            Q_PROPERTY(ParamTypeList ParamType READ getParamType WRITE setParamType)

                            public:
                            AxisCoord(QWidget *parent = 0);

                            QString GetType() const;
                            int value() const;

                            enum ParamTypeList
                            {
                            TYPE1,
                            TYPE2,
                            TYPE3
                            };

                            ParamTypeList getParamType() const;

                            QComboBox getCombobox() const;

                            ...//other code
                            @

                            1 Reply Last reply
                            0
                            • raven-worxR Offline
                              raven-worxR Offline
                              raven-worx
                              Moderators
                              wrote on last edited by
                              #14

                              hmm...please clean your project, rerun qmake and try again.

                              I don't think that i makes a difference but you can give it also a try: specify the Q_ENUMS macro after the Q_PROPERTY macros. Like in this "example":http://qt-project.org/doc/qt-4.8/properties.html#a-simple-example.

                              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                              If you have a question please use the forum so others can benefit from the solution in the future

                              1 Reply Last reply
                              0
                              • S Offline
                                S Offline
                                shootstar
                                wrote on last edited by
                                #15

                                thank you very much! when i clean my project, and add the actviex again, the property has displayed at last. I'm really very grateful to you!

                                1 Reply Last reply
                                0
                                • S Offline
                                  S Offline
                                  shootstar
                                  wrote on last edited by
                                  #16

                                  hi, raven-worx, i encounter a new problem. now, the property can be displayed, but when i modify the QAxWidget property which displayed in comboBox(include defined property), as:
                                  @ //ui_test_active.h
                                  axWidget->setProperty("FocusPolicy", QVariant(QAxWidget::NoFocus));
                                  axWidget->setProperty("ParamType", QVariant(QAxWidget::TYPE2));
                                  axWidget->setProperty("cursor", QVariant(QAxWidget::UpArrowCursor));
                                  @
                                  you know, the "FocusPolicy" and "cursor" property are the defualt property, only the "ParamType" is the new property. but when i build the project, there are errors, as:
                                  @1>E:\HNC11\test_active\test_active\GeneratedFiles\ui_test_active.h(45): error C2039: 'NoFocus' : is not a member of 'QAxWidget'
                                  1> d:\qt\qt5.0.2\5.0.2\msvc2010\include\activeqt\qaxwidget.h(59) : see declaration of 'QAxWidget'
                                  1>E:\HNC11\test_active\test_active\GeneratedFiles\ui_test_active.h(45): error C2065: 'NoFocus' : undeclared identifier
                                  1>E:\HNC11\test_active\test_active\GeneratedFiles\ui_test_active.h(46): error C2039: 'TYPE2' : is not a member of 'QAxWidget'
                                  1> d:\qt\qt5.0.2\5.0.2\msvc2010\include\activeqt\qaxwidget.h(59) : see declaration of 'QAxWidget'
                                  1>E:\HNC11\test_active\test_active\GeneratedFiles\ui_test_active.h(46): error C2065: 'TYPE2' : undeclared identifier
                                  1>E:\HNC11\test_active\test_active\GeneratedFiles\ui_test_active.h(48): error C2039: 'UpArrowCursor' : is not a member of 'QAxWidget'
                                  1> d:\qt\qt5.0.2\5.0.2\msvc2010\include\activeqt\qaxwidget.h(59) : see declaration of 'QAxWidget'
                                  1>E:\HNC11\test_active\test_active\GeneratedFiles\ui_test_active.h(48): error C2065: 'UpArrowCursor' : undeclared identifier@
                                  i have no idea to solve those error, can you help?

                                  1 Reply Last reply
                                  0
                                  • raven-worxR Offline
                                    raven-worxR Offline
                                    raven-worx
                                    Moderators
                                    wrote on last edited by
                                    #17

                                    [quote author="shootstar" date="1370658202"]
                                    you know, the "FocusPolicy" and "cursor" property are the defualt property, only the "ParamType" is the new property. but when i build the project, there are errors[/quote]

                                    the compiler error says it all: "error C2039: 'NoFocus' : is not a member of 'QAxWidget'"
                                    Your enum values are not defined in QAxWidegt but in Qt namespace. So use Qt::NoFocus and Qt::UpArrowCursor.

                                    And btw. why do you use to set these properties with with the setter for dynamic properties (i mean the setProperty() method)? I think there is nothing wrong with this code, but it is more error prone and there are qwidget setters available.

                                    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                                    If you have a question please use the forum so others can benefit from the solution in the future

                                    1 Reply Last reply
                                    0
                                    • S Offline
                                      S Offline
                                      shootstar
                                      wrote on last edited by
                                      #18

                                      thank you for your help!
                                      the code which in "ui_test_active.h" is automatically created by the system, i just modify the activeX property in Qt designer, then the system automatically generates those codes ("ui_test_active.h" file), so how can i do? whether is there some wrongs with my system configuration?

                                      1 Reply Last reply
                                      0

                                      • Login

                                      • Login or register to search.
                                      • First post
                                        Last post
                                      0
                                      • Categories
                                      • Recent
                                      • Tags
                                      • Popular
                                      • Users
                                      • Groups
                                      • Search
                                      • Get Qt Extensions
                                      • Unsolved