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

QDialog not automatically centered on parent if created before parent is shown.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Not Evaluated
    • 5.0.0
    • 4.8.4
    • None
    • Windows 7 x86, MSVC 2010

    Description

      If a child QDialog is created before its parent is added into a layout (i.e., as added to a QTabWidget), the dialog's WA_Moved attribute gets set in the process, and it therefore does not end up calling adjustPosition(parentWidget()) as it should when QDialog::setVisible() runs.

      This happens because qwidget_win.cpp's implementation of QWidgetPrivate::reparentChildren() attempts to save and restore the position of child widgets that have isWindow()==true. To do this, it saves w->pos(), then calls w->move(old_pos) even though the window had not previously been moved, which sets WA_Moved. I think it should do this only if testAttribute(WA_Moved) is true, and leave the location unset otherwise.

      The attached example project demonstrates the bug: the first tab (created before MainWindow is originally shown/laid out) centers its dialog correctly when you click on "Push Me", but subsequent tabs added to the already running tabwidget (created by hitting "New Tab") pop up at 0,0 instead.

      The bug seems to no longer be reproducible in Qt 5.0.1, but I was not able to track down the specific change that fixed it, since qwidget_win seems to have been broken up into and moved out of qtbase/gui/kernel.

      Attachments

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

        Activity

          People

            Unassigned Unassigned
            puetzk Kevin Puetz
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes