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. Find those properties of a widget which are shown in the Qt Designer
Forum Updated to NodeBB v4.3 + New Features

Find those properties of a widget which are shown in the Qt Designer

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 3 Posters 2.7k Views 3 Watching
  • 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.
  • E Eager

    @mrjj It doesn't work as expected. For example, In the designer the following QPushButton properties are not shown but they are isDesignable: frameGeometry, normalGeometry, frameSize, childrenRect, etc

    mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #4

    @Eager
    Ok, try to dump all attribute and see if you can find a red line.
    Maybe they also need to be https://doc.qt.io/Qt-5/qmetaproperty.html#isStored

    E 1 Reply Last reply
    0
    • mrjjM mrjj

      @Eager
      Ok, try to dump all attribute and see if you can find a red line.
      Maybe they also need to be https://doc.qt.io/Qt-5/qmetaproperty.html#isStored

      E Offline
      E Offline
      Eager
      wrote on last edited by
      #5

      @mrjj isWritable() removed a lot of unrelated properties but still a few appear, for example:
      windowModality, windowFilePath, windowModified, windowTitle etc.
      I used isStored too but I still see the above properties.

      mrjjM 1 Reply Last reply
      0
      • E Eager

        @mrjj isWritable() removed a lot of unrelated properties but still a few appear, for example:
        windowModality, windowFilePath, windowModified, windowTitle etc.
        I used isStored too but I still see the above properties.

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #6

        @Eager
        Hmm. Im not sure how the Designer does it.
        I tried to look around in
        https://code.woboq.org/qt5/qt-creator/src/plugins/designer/
        but found nothing.

        E 1 Reply Last reply
        0
        • mrjjM mrjj

          @Eager
          Hmm. Im not sure how the Designer does it.
          I tried to look around in
          https://code.woboq.org/qt5/qt-creator/src/plugins/designer/
          but found nothing.

          E Offline
          E Offline
          Eager
          wrote on last edited by Eager
          #7

          @mrjj Right now I am trying to look around in
          https://code.woboq.org/qt5/qttools/src/designer/src/
          Can you please look around in this one too, if you don't mind?

          mrjjM 1 Reply Last reply
          0
          • E Eager

            @mrjj Right now I am trying to look around in
            https://code.woboq.org/qt5/qttools/src/designer/src/
            Can you please look around in this one too, if you don't mind?

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #8

            @Eager
            sure. if we can find the actual property widget we should get a clue.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #9

              Hi,

              IIRC, that's because you are parsing the current class meta object for properties.

              You have go back the chain up to the "root" meta object.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              E 2 Replies Last reply
              0
              • SGaistS SGaist

                Hi,

                IIRC, that's because you are parsing the current class meta object for properties.

                You have go back the chain up to the "root" meta object.

                E Offline
                E Offline
                Eager
                wrote on last edited by Eager
                #10

                @SGaist For finding only those properties of QPushButton which the Qt Designer displays in Property Editor, I am currently doing like this:

                    qDebug()<<qPrintable("Widget: QPushButton");
                    QObject *object = new QPushButton;
                    const QMetaObject *metaobject = object->metaObject();
                    for (int i=0; i<metaobject->propertyCount(); ++i) {
                        QMetaProperty metaproperty = metaobject->property(i);
                        qDebug()<<metaproperty.isStored();
                        if(metaproperty.isWritable() && metaproperty.isDesignable()) {
                            qDebug()<<qPrintable(QString(metaproperty.name()) + " : " + QString(metaproperty.typeName()));
                        }
                    }
                

                Can you please point out where I am doing wrong?

                1 Reply Last reply
                0
                • SGaistS SGaist

                  Hi,

                  IIRC, that's because you are parsing the current class meta object for properties.

                  You have go back the chain up to the "root" meta object.

                  E Offline
                  E Offline
                  Eager
                  wrote on last edited by
                  #11

                  @SGaist

                  You have go back the chain up to the "root" meta object.

                  How can I do this? I wish I knew this concept! :(
                  Can you please explain this or share a sample code?
                  I am already highly obliged!

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #12

                    To go through the chain, use QMetaObject::superClass.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    E 1 Reply Last reply
                    1
                    • SGaistS SGaist

                      To go through the chain, use QMetaObject::superClass.

                      E Offline
                      E Offline
                      Eager
                      wrote on last edited by
                      #13

                      @SGaist I tried that and I noticed that QMetaObject::superClass() gives me the properties of the base classes of the widget in question. I went through the chain in a loop and displayed the properties of each level and I found that properties like windowModality, windowFilePath, windowModified, windowTitle etc. are defined inside the base classes alongwith many other which should be displayed for the QPushButton in the Qt Designer.
                      I think Qt Designer uses some kind of fuzzy logic and somehow suppresses some of the properties for the child widgets.

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #14

                        What are the differences ?

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        E 1 Reply Last reply
                        0
                        • E Eager

                          How can I find only those properties of a widget (e.g. QPushButton) which Qt Designer shows in the Property Editor?
                          I can find all properties including those which are not shown in the Qt Designer using the following code:

                              // Print all available properties of a Widget:
                              qDebug()<<qPrintable("Widget: QPushButton");
                              QObject *object = new QPushButton;
                              const QMetaObject *metaobject = object->metaObject();
                              for (int i=0; i<metaobject->propertyCount(); ++i) {
                                  QMetaProperty metaproperty = metaobject->property(i);
                                  const char *name = metaproperty.name();
                                  QVariant value = object->property(name);
                                  qDebug()<<qPrintable("\n" + QString(name) + "\n" + QString(value.typeName()));
                              }
                          
                          E Offline
                          E Offline
                          Eager
                          wrote on last edited by Eager
                          #15

                          At last I found a working solution. Of course, it has some limitations but works for my use case.

                              // Print all those properties of a widget which are shown in the Qt Designer:
                          
                              /* Main Container is the widget having no parent.
                               * Main Container has the following extra properties:
                               *  - windowTitle
                               *  - windowIcon
                               *  - windowIconText
                               *  - windowOpacity
                               *  - windowModified
                               *  - windowFilePath
                               *
                               * In a ui form there can only be one Main Container.
                               *
                               * As we want to get the properties of the widgets which are not designed/intended
                               * to be used as Main Container of a ui form so to avoid getting the above extra
                               * properties we make them children of a fake main container widget.
                               *
                               * Qt Designer does not show read only properties so make sure you display only those
                               * properties which are both readable and writable.
                               *
                               * Note also that property visibility in the Qt Designer can be set ON and OFF by
                               * other properties. For example checked property is designable only if boolean
                               * property setCheckable is set to true.
                               *
                               * As you can notice in the files:
                               * qt5/qttools/src/designer/src/lib/shared/qdesigner_propertysheet.cpp
                               * qt5/qttools/src/designer/src/components/formeditor/qdesigner_resource.cpp
                               * that windowModality is set Visible only for the Main Container so manually remove that
                               * property whenever you find it for the children widgets.
                               */
                                 QWidget *fakeMainContainerWidget = new QWidget(); // No parent means main container.
                                 QObject *object = new QPushButton(fakeMainContainerWidget);
                                 const QMetaObject *metaobject = object->metaObject();
                                 qDebug() << qPrintable("-==" + QString(metaobject->className()) + " ==-");
                                 for (int i=0; i<metaobject->propertyCount(); ++i) {
                                     QMetaProperty metaproperty = metaobject->property(i);
                                     bool isReadOnly = metaproperty.isReadable() && !metaproperty.isWritable();
                                     bool isWinModal = metaproperty.name() == QString("windowModality"); // removed windowModality manually
                                     if( !isReadOnly && metaproperty.isDesignable(object) && !isWinModal ) {
                                         qDebug() <<  qPrintable(QString(metaproperty.name()) + " : " + QString(metaproperty.typeName()));
                                     }
                                 }
                          
                          1 Reply Last reply
                          0
                          • SGaistS SGaist

                            What are the differences ?

                            E Offline
                            E Offline
                            Eager
                            wrote on last edited by Eager
                            #16

                            @SGaist I came up with a solution and I have posted it in this thread.

                            1 Reply Last reply
                            1

                            • Login

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