Custom Q_PROPERTY not showing in QT Designer



  • 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]



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



  • 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.



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



  • Ah, yes, of course.



  • 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.



  • 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.



  • 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.



  • 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.



  • 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.



  • 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.



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

    I was wondering why SetProperty only works in the constructor.

    Thanks everyone.



  • [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.



  • [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.



  • Lets not start an argument out of nothing.

    I appreciate the help guys :)



  • [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.



  • [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.



  • [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 !


Log in to reply
 

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