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. Custom Q_PROPERTY not showing in QT Designer
QtWS25 Last Chance

Custom Q_PROPERTY not showing in QT Designer

Scheduled Pinned Locked Moved General and Desktop
18 Posts 3 Posters 12.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.
  • C Offline
    C Offline
    ctn123
    wrote on last edited by
    #1

    Hi,

    I have made simple Q_PROPERTY's show up

    e.g.
    @
    Q_ENUMS(LINESTYLE);
    Q_PROPERTY(LINESTYLE LineStyle READ getLineStyle WRITE setLineStyle);
    Q_PROPERTY(QPoint Pos READ getPos WRITE setPos);
    @
    I'm having trouble with a custom Q_PROPERTY

    @struct CustomType
    {
    int i;
    };

    Q_DECLARE_METATYPE(CustomType);@

    The class it is in is defined as:

    @class QDESIGNER_WIDGET_EXPORT MyClass : public QGraphicsView
    {
    ...
    Q_PROPERTY(CustomType customType READ getcustomType WRITE setcustomType);
    ...
    CustomType getcustomType() const { return customType; }
    void setcustomType(const CustomType &val) { customType = val; }
    ...
    }
    @
    I've tried registering it as well with qRegisterMetaType<CustomType>("CustomType");

    What I doing something wrong?

    [Edit: use @-tags for code; Andre]

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      Designer does not know what editor to use for your custom type.

      http://www.catb.org/~esr/faqs/smart-questions.html

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

        Really?
        Designer can not create an editor to select the options from an enum that has been declared using Q_ENUMS? That would be quite disapointing IMHO. I mean, even an open source, third party component like "Yape":http://qt-apps.org/content/show.php/yape+(Yet+another+property+editor)?content=100064 can do that. I use an extended version of Yape in my own project as a property editor, and that works nicely for cases like this.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          That's correct for the enums (they show up according to the OP), but not for struct CustomType.

          http://www.catb.org/~esr/faqs/smart-questions.html

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

            Ah, yes, of course.

            1 Reply Last reply
            0
            • C Offline
              C Offline
              ctn123
              wrote on last edited by
              #6

              That's a pity.

              I need to figure out a way to display custom properties.

              I tried SetProperties to create dynamic properties that show up in the Designer, but it's hit an miss.

              SetProperty("Test", 123) - to add
              SetProperty("Test", QVariant()); - to remove

              It works well in the constructor, but anywhere else it seems to correctly add/remove the property as it fires the change event but the property in the Designer doesn't get updated for some reason.

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #7

                You cannot add custom properties in the sense of a property type that is not built in to Qt. Qt Designer has only editors for property types it knows. If you add your own property type (read: class) - what editor should Designer use?

                Other properties with builtin types are possible if you declare them at compile time with Q_PROPERTY, but you know this already.

                Dynamic properties are no solution, you still have the very same property regarding the editor.

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  ctn123
                  wrote on last edited by
                  #8

                  I' guessing by doing the following, it is using known QT types.

                  Using SetProperty(“Test”, 123) – does add a dynamic property in the constructor.
                  Using SetProperty(“Test”, QVariant()) – does remove a dynamic property in the constructor.

                  I just don't understand why it doesn't work properly when not in the constructor. It seems to change the property but doesn't refresh/repaint the value in the QT Property Editor.

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    goetz
                    wrote on last edited by
                    #9

                    I'm lost. I just don't understand what you are trying to do. Why do you use dynamic properties in the constructor? This all is plain weird.

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    1 Reply Last reply
                    0
                    • C Offline
                      C Offline
                      ctn123
                      wrote on last edited by
                      #10

                      I'm using it in the constructor to test how it works since it doesn't seem to properly work any where else.

                      In other places apart from the constructor, it seems to change the value and fire the change events, but the property editor in the designer does not get updated with the changed value.

                      I'm trying to display a custom type in the property editor but it seems not possible.

                      Failing that, a set of dynamic properties that gets added and removed would suffice. This function seems to be only fully working in the constructor of the QGraphicsView of the QT Designer Plugin.

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

                        I think you (ctn123) need to read up on QDesignerPropertySheetExtension and QDesignerDynamicPropertySheetExtension. The documentation of the first one states:

                        [quote]All widgets have a default property sheet which populates Qt Designer's property editor with the widget's properties (i.e the ones defined with the Q_PROPERTY() macro). But QDesignerPropertySheetExtension also provides an interface for creating custom property sheet extensions.[/quote] (highlight by Andre)

                        That sounds like what you need: the ability to provide your own editor.

                        1 Reply Last reply
                        0
                        • C Offline
                          C Offline
                          ctn123
                          wrote on last edited by
                          #12

                          Yep, I managed to do that already with QDesignerPropertySheetExtension and QDesignerDynamicPropertySheetExtension.

                          I was wondering why SetProperty only works in the constructor.

                          Thanks everyone.

                          1 Reply Last reply
                          0
                          • G Offline
                            G Offline
                            goetz
                            wrote on last edited by
                            #13

                            [quote author="ctn123" date="1298635046"]I'm using it in the constructor to test how it works since it doesn't seem to properly work any where else.
                            [/quote]

                            It's obvious that you are trying something. Still you fail to explain what you are trying. Still you fail to tell us what you expect the code to do. If you are able to tell a compiler to add one and two and store it in a variable, you should be able to tell us what you want to do. And no, any fluffy "work properly" does not count.

                            [quote author="ctn123" date="1298635046"]I'm trying to display a custom type in the property editor but it seems not possible.
                            [/quote]

                            Quelle surprise! I vaguely remember that was stated already - more than once, indeed, but still you fail to read and understand what we have written. I'm tired to write and explain it again a third time.

                            http://www.catb.org/~esr/faqs/smart-questions.html

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

                              [quote author="Andre" date="1298635114"][quote]All widgets have a default property sheet which populates Qt Designer's property editor with the widget's properties (i.e the ones defined with the Q_PROPERTY() macro). But QDesignerPropertySheetExtension also provides an interface for creating custom property sheet extensions.[/quote] (highlight by Andre)

                              That sounds like what you need: the ability to provide your own editor.
                              [/quote]

                              But it seems that it is not. I have done some more searching, but I can not find a way to create and plug in your own editor into the Qt Designer property editor. That means that custom types will not show up, unless I missed the documentation on how to do it completely.

                              1 Reply Last reply
                              0
                              • C Offline
                                C Offline
                                ctn123
                                wrote on last edited by
                                #15

                                Lets not start an argument out of nothing.

                                I appreciate the help guys :)

                                1 Reply Last reply
                                0
                                • C Offline
                                  C Offline
                                  ctn123
                                  wrote on last edited by
                                  #16

                                  [quote author="Andre" date="1298637349"][quote author="Andre" date="1298635114"][quote]All widgets have a default property sheet which populates Qt Designer's property editor with the widget's properties (i.e the ones defined with the Q_PROPERTY() macro). But QDesignerPropertySheetExtension also provides an interface for creating custom property sheet extensions.[/quote] (highlight by Andre)

                                  That sounds like what you need: the ability to provide your own editor.
                                  [/quote]

                                  But it seems that it is not. I have done some more searching, but I can not find a way to create and plug in your own editor into the Qt Designer property editor. That means that custom types will not show up, unless I missed the documentation on how to do it completely. [/quote]

                                  It does however let you add and remove dynamic properties and have it update and refresh properly in the property editor.

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

                                    [quote author="ctn123" date="1298637687"]
                                    It does however let you add and remove dynamic properties and have it update and refresh properly in the property editor.
                                    [/quote]

                                    Yes, but the problem was in showing your custom property (a struct), not in showing a dynamic property, was it?

                                    Edit: I just got confirmation that Designer (and uic) do not support custom property types. No way to conjure up an editor for your custom struct. And even if you could, uic does not support it either, so it would not be translated into code.

                                    1 Reply Last reply
                                    0
                                    • C Offline
                                      C Offline
                                      ctn123
                                      wrote on last edited by
                                      #18

                                      [quote author="Andre" date="1298639422"]Yes, but the problem was in showing your custom property (a struct), not in showing a dynamic property, was it?

                                      Edit: I just got confirmation that Designer (and uic) do not support custom property types. No way to conjure up an editor for your custom struct. And even if you could, uic does not support it either, so it would not be translated into code.
                                      [/quote]

                                      Thanks for finding out for me.

                                      Yes the custom property (a struct) was not showing up as a property via Q_PROPERTY as well as a dynamic property via QDesignerDynamicPropertySheetExtension to add and QDesignerPropertySheetExtension to modify.

                                      This solves the problem where the property editor was not refreshing a property's value for a QT supported type.

                                      I suspected that, I've tried many options short of changing the QT Designer source code. I can see how to change the source code to do this, but I'd prefer not to. My backup is to use Dynamic Properties to invidually load all the supported types, instead of having them in a custom property (struct). Alternatively I could use Q_PROPERTY with designable set to false and use QDesignerPropertySheetExtension to toggle the visibility so it wont show under the "Dynamic Properties" section. It won't be grouped but that's ok. It does mostly the same thing, only exception that it is not grouped in the property editor.

                                      i.e.

                                      @- i

                                      • j
                                      • k@

                                      vs

                                      If custom types were to work:

                                      @-

                                      • i
                                      • j
                                      • k@

                                      My custom type was going to be a struct with a bunch of QT supported types.

                                      Now that it correctly refreshes in the property editor, my problem is mostly solved :)

                                      Sorry if I seem like I'm asking stupid questions, I started QT a few days ago.

                                      Thanks again !

                                      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