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. Analog of modal QDialog in QML
Forum Updated to NodeBB v4.3 + New Features

Analog of modal QDialog in QML

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 3 Posters 3.1k 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.
  • V Offline
    V Offline
    Varvara
    wrote on last edited by
    #1

    How can i do this only in QML without QDIalog?

    @
    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);

    QDialog dialog;
    QVBoxLayout layout(&dialog);
    QPushButton button1(QObject::tr("button1"), &dialog);
    QPushButton button2(QObject::tr("button2"), &dialog);
    
    layout.addWidget(&button1);
    layout.addWidget(&button2);
    
    QString windowPath;
    
    QObject::connect(&button1, &QPushButton::clicked, [&dialog, &windowPath] {
        dialog.accept();
        windowPath = QStringLiteral("qrc:///window1.qml");
    });
    
    QObject::connect(&button2, &QPushButton::clicked, [&dialog, &windowPath] {
        dialog.accept();
        windowPath = QStringLiteral("qrc:///window2.qml");
    });
    
    if (dialog.exec() == QDialog::Rejected)
        return 0;
    
    QQmlApplicationEngine engine;
    engine.load(QUrl(windowPath));
    
    return app.exec();
    

    }
    @

    1 Reply Last reply
    0
    • timdayT Offline
      timdayT Offline
      timday
      wrote on last edited by
      #2

      My guess would be you could create a "QML Window":http://qt-project.org/doc/qt-5/qml-qtquick-window-window.html and set its "modality property":http://qt-project.org/doc/qt-5/qml-qtquick-window-window.html#modality-prop to one of Qt.WindowModal or Qt.ApplicationModal. I've never done more than one-window QML myself though.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bootchk
        wrote on last edited by
        #3

        The question is fuzzy: do you mean

        "how do I embed a QML dialog in a C++ app?"

        or "how do I get the same blocking semantics as an exec() call?"

        If you mean the former, then read the docs under "embedding" or "interfacing C++ to QML." And then you can embed a QML Window or QuickControl Dialog.

        If you mean the latter, its not as easy as setting the modality property of the QML Window or Dialog:

        bq. Modality does not mean that there are any blocking calls to wait for the dialog to be accepted or rejected: only that the user will be prevented from interacting with the parent window or the application windows until the dialog is dismissed.

        In other words, after your embedding C++ code invokes the dialog (say by sending a signal to a delegate that calls QML Dialog.open()), I think your embedding code (your C++ event loop) continues, it doesn't wait for the QML dialog to be accepted or canceled by the user.

        In other words, there is no equivalent in QML to the QDialog.exec() C++ call. To get the same semantics, you must connect the accepted/canceled signals. I could be wrong.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          bootchk
          wrote on last edited by
          #4

          The question is fuzzy: do you mean

          "how do I embed a QML dialog in a C++ app?"

          or "how do I get the same blocking semantics as an exec() call?"

          If you mean the former, then read the docs under "embedding" or "interfacing C++ to QML." And then you can embed a QML Window or QuickControl Dialog.

          If you mean the latter, its not as easy as setting the modality property of the QML Window or Dialog:

          bq. Modality does not mean that there are any blocking calls to wait for the dialog to be accepted or rejected: only that the user will be prevented from interacting with the parent window or the application windows until the dialog is dismissed.

          In other words, after your embedding C++ code invokes the dialog (say by sending a signal to a delegate that calls QML Dialog.open()), I think your embedding code (your C++ event loop) continues, it doesn't wait for the QML dialog to be accepted or canceled by the user.

          In other words, there is no equivalent in QML to the QDialog.exec() C++ call. To get the same semantics, you must connect the accepted/canceled signals. I could be wrong.

          1 Reply Last reply
          0
          • B Offline
            B Offline
            bootchk
            wrote on last edited by
            #5

            I just read "this post":http://www.qtcentre.org/archive/index.php/t-41193.html?s=4f0051811b94e81a668de909e4c9df15, which suggested that to get the blocking semantics you should implement a QDialog with blocking semantics, having your QML as the contents of the QDialog. That might give the blocking semantics, but I don't think it would give you the benefit of a native dialog look-and-feel that QML Dialog ought to give you.

            1 Reply Last reply
            0
            • B Offline
              B Offline
              bootchk
              wrote on last edited by
              #6

              I just read "this post":http://www.qtcentre.org/archive/index.php/t-41193.html?s=4f0051811b94e81a668de909e4c9df15, which suggested that to get the blocking semantics you should implement a QDialog with blocking semantics, having your QML as the contents of the QDialog. That might give the blocking semantics, but I don't think it would give you the benefit of a native dialog look-and-feel that QML Dialog ought to give you.

              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