[Development] RFC: Scriptable Widgets

Fabian Kosmale fabian.kosmale at qt.io
Thu Nov 28 16:02:48 CET 2024


Note however that using QMetaType has the limitation that it will only 
allow calling the default constructor. While all widgets should be 
default constructible, you might want to construct e.g. 
`QDialogButtonBox::QDialogButtonBox` with some specific button). Could 
be worked around in the bindings, though.

Fabian

On 28.11.24 15:45, Volker Hilsheimer via Development wrote:
>> On 28 Nov 2024, at 15:01, André Somers via Development <development at qt-project.org> wrote:
>>
>> Hi Marcus,
>>
>> On 28-11-2024 14:29, Marcus Tillmanns via Development wrote:
>>> Hi Shawn,
>>>
>>>> On 28. Nov 2024, at 13:15, Shawn Rutledge via Development <development at qt-project.org> wrote:
>>>>
>>>>
>>>>> On Nov 28, 2024, at 09:08, Fabian Kosmale via Development <development at qt-project.org> wrote:
>>>>> - Some are already (indirectly) exposed via Q_PROPERTY; should anyone decide to expose those Widgets to QML (or some other language binding working on the meta-object system), this would cause some friction because there will be name clashes (QWidget::geometry() vs the geometry property).
>>>> Indeed; given that the UI designer application, and QUiLoader, are able to dynamically instantiate every kind of widget, and all the interesting properties are, well, properties, it seems doubtful that there are many things that you couldn’t already do in a scripting language either.  And some property setters are already slots, which already makes them invokable, and is also a bit redundant already (if QProperty can set the property, the main reason for making the setter into a slot besides is to be able to connect a signal to it, right?)
>>> QUiLoader seems to have a fixed list of Widgets it can instantiate? (“widgets.table”) And for custom widgets it expects you to implement QDesignerCustomWidgetInterface.
>>>
>>> And then for the properties, most is there you are right and I was starting to think it should all be easy, but pretty important stuff like “QWidget::show()” is not covered by a property sadly. I will investigate how much of the important stuff is missing first, maybe just setting up a list of classes and their Constructors, plus the important QWidget functions is small enough that I no longer wish for Q_INVOKABLE all the things :)
>>
>> You may want to look into leveraging Declarative Widgets. This is an experimental/PoC implementation of using widgets from QML. Rather than extending the widgets classes themselves, it uses the extension mechanism to provide the missing features from the QML (scriptable) perspective.
>>
>> Cheers,
>>
>> André
> 
> 
> With the meta type system, you can construct any Q_OBJECT-type by name, as long as it’s registered:
> 
> #include <QtWidgets>
> 
> int main(int argc, char *argv[])
> {
>      QApplication app(argc, argv);
> 
>      qRegisterMetaType<QPushButton>("QPushButton");
> 
>      const QMetaType pbType = QMetaType::fromName("QPushButton");
>      QObject *pb = static_cast<QObject *>(pbType.create());
>      Q_ASSERT(pb);
>      pb->setProperty("text", "Ok");
>      pb->setProperty("visible", true);
> 
>      return app.exec();
> }
> 
> 
> The call to qRegisterMetaType could be done in the code that implements the binding.
> 
> Volker
> 

-- 
Fabian Kosmale
Manager R&D

The Qt Company GmbH
Erich-Thilo-Str. 10
D-12489 Berlin
fabian.kosmale at qt.io
+49 1638686070


More information about the Development mailing list