Placing QML window over Qt dialog

  • Hi,
    I created a busy indicator in qml and want to place it over a dialog. Currently this is what I have:
    under qml.qrc Busy.qml (and BusyForm.ui):

    import QtQuick 2.6
    import QtQuick.Window 2.2
    Window {
        visible: true
        width: 100
        height: 100
        modality: Qt.ApplicationModal
    flags: Qt.FramelessWindowHint
        BusyForm {
            Image {
                id: container
                source: "images/busy.png";
                NumberAnimation on rotation {
                    running: container.visible
                    from: 0; to: 360;
                    loops: Animation.Infinite;
                    duration: 1200

    In main.cpp:

    #include "mainwindow.h"
    #include "ui_display.h"
    #include <QApplication>
    #include <QQmlApplicationEngine>
    int main(int argc, char* argv[]) {
      QApplication a(argc, argv);
      MainWindow w;
      QQmlApplicationEngine engine;
      if (engine.rootObjects().isEmpty())
        return -1;;
      return a.exec();

    The project builds without error. How can I call Busy.qml from a dialog so the busy widget would appear above the dialog?
    Thank you.

  • You would like to place the your busy.qml over object 'w' ? Object 'w' is an instance MainWindow. Is the MainWindow inherited from QMainWindow/QWidget ? if yes, this means that you are mixing Qt widget and QML. Please look at this topic.

    Also you should create component & object from Busy.qml using Qt.createComponen & createObject. After that you should be able do this.

  • @dheerendra
    There is an other dialog over which I would like to place the qml.

  • what is that 'other dialog' means ?. Is it QML component or QWidget based dialog ?

  • @dheerendra
    It is a QWidget based dialog.

  • You can embed the QML Window inside the QWIdget based UI. Hope you have looked createWindowContainer function of QWidget.

  • Thank you.

Log in to reply

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