Qwidgets in QML
Hi,
is it somehow possible to use Native QtWidgets (like a QCombobox) in a QDeclarativeItem? I know about the labs projects and things about QML controls. but I need a stable solution.
thanks
9 replies
There are couple of things..
1) Do you want to create instances of native qt widgets inside qml or
2) You want to make a concrete native qt widget create in C++ class and make it available inside qml??
The second one is easy and make sense to do it. But first method is bit hard as mostly not all useful properties/methods are exposed to meta system via Q_PROPERTY/Q_INVOKABLE, so are not available inside qml.
Qt comes with an example that shows how to embedded widgets in qml:
examples/declarative/cppextensions/qwidgets
There are a couple of problems though:
You can not nest widgets with QML easily.
There is a clash of philosophies. In C++ you keep pointers to widgets to manipulate them. In QML visual items adapt to property changes. Having pointers to widgets breaks the separation between C++ (back end) and qml (front end).
you can refer to http://doc.qt.nokia.com/4.7/qdeclarativeexamples.html#c-extensions
I’ve had all kind of troubles (painting artefacts, bad performance, …) with embedding QWidgets in QML scenes. It just does not work very well.
I guess the Qml Desktop Components won’t become official/stable before Qt 5 so for desktop applications that must have a native look and feel I would recommend using the classic QWidget approach.
You must log in to post a reply. Not a member yet? Register here!





