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

Reparenting of QDialog leads to wrong Z-ordering

XMLWordPrintable

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

      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

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

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

              Created:
              Updated:

                There are no open Gerrit changes