C
C
cerevra2014-08-12 08:33:03
Qt
cerevra, 2014-08-12 08:33:03

How to group properties (PROPERTY) of a custom widget (custom widget plugin) for Qt Designer?

I am using Qt 5.3.1. You need to make your own widget, which you can put in Qt Designer. Qt uses a specific term for this: custom widget plugin. One of the requirements for it is to make it possible to customize it in Designer, and even in a certain way. It is necessary to make several groups of properties. By groups (maybe there is a more correct term - feel free to say) I mean such blocks of data: which can contain bool, string, int, etc. values.
4fe5a3895c75497eb24112e5ac296300.png
Found two ways to set properties.
1) Qt XML
Documentation
Excerpt from there:

QString AnalogClockPlugin::domXml() const
 {
     return "<ui language=\"c++\">\n"
            " <widget class=\"AnalogClock\" name=\"analogClock\">\n"
            "  <property name=\"geometry\">\n"
            "   <rect>\n"
            "    <x>0</x>\n"
            "    <y>0</y>\n"
            "    <width>100</width>\n"
            "    <height>100</height>\n"
            "   </rect>\n"
            "  </property>\n"
            "  <property name=\"toolTip\" >\n"
            "   <string>The current time</string>\n"
            "  </property>\n"
            "  <property name=\"whatsThis\" >\n"
            "   <string>The analog clock widget displays the current time.</string>\n"
            "  </property>\n"
            " </widget>\n"
            "</ui>\n";
 }

But I don't see a way to bind the property I'm adding there to the widget's attributes or methods. There is also a problem with "rect" type blocks - where is the description for them?
2) Q_PROPERTY
Widget on Q_PROPERTY
Here the connection with the widget is logical and clear. But it is not known how to make a group.
class QDESIGNER_WIDGET_EXPORT LED : public QWidget
 {
   Q_OBJECT
 
   Q_PROPERTY(double diameter READ diameter WRITE setDiameter) // mm
   Q_PROPERTY(QColor color READ color WRITE setColor)
   Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment)
   Q_PROPERTY(bool state READ state WRITE setState)
   Q_PROPERTY(bool flashing READ isFlashing WRITE setFlashing)
   Q_PROPERTY(int flashRate READ flashRate WRITE setFlashRate)

I'm at a dead end. Someone tell me?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
cerevra, 2014-08-12
@cerevra

QDesignerPropertySheetExtension creates groups like this:
And apparently, the grouping I need exists only for built-in types. Absolutely unhealthy.
Thanks for the direction

T
tzlom, 2014-08-12
@tzlom

I recommend looking at the QtCreator / QtDesigner sources, but you can start from here:
https://qt-project.org/doc/qt-5/qdesignerpropertys...
https://qt-project.org/doc/qt-4.7/designer- https: //qt-project.org/doc/qt-4.7/qdesignerdynamic
...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question