Using QML to develop a component



  • I have been going through the Qt Quick and QML tutorials, and all the examples show some standard GUI executable launching, the settings of which are configured in the QML file.

    Is it possible to develop only a component of the overall GUI in QML? For example, I have a main window, with the menu bar showing on top (in OS X). When a certain option is clicked from the menu bar, I want a detailed dialog box to open, showing lots of rich content. Of course I know there are other ways to do this, but is it possible to fire the new dialog window within the main window (which didn't use QML) using QML?


  • Moderators

    Yes, you can run QML code from withing a QtWidgets application by using QWidget::createWindowContainer().

    You can also run QML-only apps by using the qml binary located in <QTDIR>/qtbase/bin.



  • Yes, its possible, but it is new territory with few examples. Yes createWindowContainer() enables it, but it is not a complete solution. For example, does show() such a QWidget container (containing a QML Dialog) make the dialog execute? Or do you also need to interface your C++ code to the QML objects so that you can call Dialog.open() method of the QML?

    Also, do you need to parent such a container QWidget to your main window QWidget? Or do you need to parent the contained QQuickView to the QWindow of your app? (See discussions about QWidget parent tree versus QWindow/QObject parent tree.)

    The general question is usually answered using the phrase "embedding QML in C++" or "embedding QML in QWidgets."



  • Yes, its possible, but it is new territory with few examples. Yes createWindowContainer() enables it, but it is not a complete solution. For example, does show() such a QWidget container (containing a QML Dialog) make the dialog execute? Or do you also need to interface your C++ code to the QML objects so that you can call Dialog.open() method of the QML?

    Also, do you need to parent such a container QWidget to your main window QWidget? Or do you need to parent the contained QQuickView to the QWindow of your app? (See discussions about QWidget parent tree versus QWindow/QObject parent tree.)

    The general question is usually answered using the phrase "embedding QML in C++" or "embedding QML in QWidgets."


  • Moderators

    Qt 5.4 also comes with new QQuickWidget, which is the preferred solution to creating a window container.


  • Moderators

    Qt 5.4 also comes with new QQuickWidget, which is the preferred solution to creating a window container.


Log in to reply
 

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