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. Modal Dialog Problem with QtQuickControls2

Modal Dialog Problem with QtQuickControls2

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 3 Posters 3.0k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    StoatPatronus
    wrote on last edited by StoatPatronus
    #1

    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();
    }
    
    E 1 Reply Last reply
    2
    • S StoatPatronus

      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();
      }
      
      E Offline
      E Offline
      Eeli K
      wrote on last edited by
      #2

      @StoatPatronus Set the closePolicy property of the Dialog.

      S 1 Reply Last reply
      3
      • E Eeli K

        @StoatPatronus Set the closePolicy property of the Dialog.

        S Offline
        S Offline
        StoatPatronus
        wrote on last edited by
        #3

        @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

        1 Reply Last reply
        1
        • R Offline
          R Offline
          rrxmzl
          wrote on last edited by
          #4

          check this doc
          https://doc.qt.io/qt-6/qml-qtquick-controls-popup.html#closePolicy-prop

          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