Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to show Dialog window from QML plugin
Forum Updated to NodeBB v4.3 + New Features

How to show Dialog window from QML plugin

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 171 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LeoAbalckin
    wrote on last edited by
    #1

    I have QML plugin and qml-file inside it like

    import QtQuick 2.0
    import QtQuick.Controls
    import QtQuick.Dialogs
    
    Window {
        id: errorDialog
        objectName: "errorDialog"
        width: 300
        height: 200
        modality: Qt.ApplicationModal
        visible: true
    
        property string errorMessage: ""
    
        Text {
            text: errorMessage
            anchors.centerIn: parent
        }
    
        Button {
            text: "OK"
            anchors.bottom: parent.bottom
            anchors.horizontalCenter: parent.horizontalCenter
            onClicked: errorDialog.close()
        }
    }
    

    This plugin has some class (FileListModel) inside and some method that tries to load this window and show it in modal mode:

    Q_INVOKABLE void FileListModel::ShowDlg(const QString& name)
    
        QQmlComponent component(&m_Engine, QUrl(QStringLiteral("qrc:/ErrorDialog.qml")));
    
        if (component.isError()) {
            qWarning() << component.errors();
        }
    
        QObject *dialog = component.create();
    
        QQuickWindow* window = qobject_cast<QQuickWindow*>(dialog);
    
        if (window) {
            window->setProperty("errorMessage", QString("Unknown file type: %1").arg(name));
            window->setModality(Qt::ApplicationModal);
            qWarning() << "modaity " << window->isModal(); // true here
            window->show();
        }
        else {
            qWarning() << "Failed to cast to QQuickWindow";
        }
    
    

    Here m_Engine has type QQmlApplicationEngine.

    And I have a main application uses this plugin. This app has its own qml and on selecting some element calls FileListModel::ShowDlg.

    The problem is this window is not modal. I also tried to use Dialog instead of Window in qml and call "open" but in this case dialog is not shown at all.

    So, is it possible to make this window modal or use Dialog in the right way?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved