Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-77134

Reparenting of QDialog leads to wrong Z-ordering

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P1: Critical
    • None
    • 5.9.3
    • None
    • Windows 10
    • Windows

    Description

      In the following example, dialog 'Foo' is being drawn under its parent, the window is modal, active and eats user input, yet it is drawn under 'Bar'.
      Note that this only happens these two dialogs are first opened in child-parent relationship and then the relationship is reversed.

      #include <QApplication>
      #include <QDialog>
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
      
          QDialog mainDialog; mainDialog.setWindowTitle("mainDialog"); mainDialog.resize(500, 500);
          QDialog bar(&mainDialog); bar.setWindowTitle("bar"); bar.resize(400, 300);
          QDialog foo(&mainDialog); foo.setWindowTitle("foo"); foo.resize(300, 400);
      
          mainDialog.open();
      
          // parent one dialog to another and open them
          foo.open();
          bar.setParent(&foo, bar.windowFlags());
          bar.open();
      
          // close dialogs
          bar.reject();
          foo.reject();
      
          // re-order parent-child and open again
          bar.setParent(&mainDialog, bar.windowFlags());
          bar.open();
      
          foo.setParent(&bar, foo.windowFlags());
          foo.open();
      
          return a.exec();
      }
      

      Changing the line:

      bar.setParent(&mainDialog, bar.windowFlags());
      

      to

      auto flags = bar.windowFlags();
      bar.setParent(&mainDialog);
      bar.setWindowFlags(flags);
      

      seems to solve the issue, but it causes another bug - https://bugreports.qt.io/browse/QTBUG-70240

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            danprinc danprinc
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes