Modal Dialog Problem with QtQuickControls2



  • I'm writing a QML application using QtQuickControls2 (QC2). When I create a QC2 Dialog with the modal property set to true and use the dialog's open() method, my main window is grayed out and the dialog appears, but if I click anywhere in the grayed out window the dialog disappears.

    If I try the same test with a QtQuick.Dialogs dialog and set its modality property to Qt.WindowModal, the dialog behaves as expected.

    I have tried this on both the desktop version of Qt 5.8.0, and on a Raspberry Pi (without Xorg/X11).

    Is there some weird parenting issue going on?

    Here's a screen capture of the behaviour: http://imgur.com/a/DZRVZ

    And my example code (also available at https://bitbucket.org/johnwoltman/quickcontrolsmodalitytest)

    main.qml

    
    /* Demonstrates that QuickControls2 Dialog's don't support modality
     *
     */
    import QtQuick 2.7
    import QtQuick.Controls 2.0
    import QtQuick.Layouts 1.0
    
    ApplicationWindow {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        DialogWithQC2 {
            id: dialogThatShouldBeModal
            modal: true
        }
    
        DialogWithQC1 {
            id: dialogThatIsModal
        }
    
        Text {
            id: explanation
            text: "Demonstrates that QtQuick.Controls 2.1 dialogs aren't modal";
        }
    
        Button {
            id: button1
            onClicked: dialogThatShouldBeModal.open()
            x: 0
            y: explanation.height + 10
            text: "Show me a dialog that SHOULD be modal"
        }
    
        Button {
            onClicked: dialogThatIsModal.open()
            x: 0
            y: button1.height + 40
            text: "Show me a REAL modal dialog"
        }
    }
    

    DialogWithQC1.qml

    import QtQuick 2.4
    import QtQuick.Controls 1.4
    import QtQuick.Dialogs 1.2
    
    Dialog {
        modality: Qt.WindowModal
        Rectangle {
    
            width: 500
            height: 200
            border.width: 1
            color: "yellow"
            Text {
                text: "I am modal"
            }
            Button {
                y: 30
                text: "Close me"
                onClicked: dialogThatIsModal.close()
            }
        }
    }
    

    DialogWithQC2.qml

    import QtQuick 2.4
    import QtQuick.Controls 2.1
    
    Dialog {
        modal: true
        Rectangle {
    
            width: 500
            height: 200
            border.width: 1
            color: "yellow"
            Text {
                text: "I want to be modal, but if you click in the gray area I'll disappear :-("
            }
            Button {
                y: 30
                text: "Close me"
                onClicked: dialogThatShouldBeModal.close()
            }
        }
    }
    

    main.cpp

    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    
    int main(int argc, char *argv[])
    {
        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
        QGuiApplication app(argc, argv);
    
        QQmlApplicationEngine engine;
        engine.load(QUrl(QLatin1String("qrc:/main.qml")));
    
        return app.exec();
    }
    


  • @StoatPatronus Set the closePolicy property of the Dialog.



  • @Eeli-K That's exactly what I needed, thanks! Someone else filed a bug report on this a few days ago: https://bugreports.qt.io/browse/QTBUG-60358


Log in to reply
 

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