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

_q_showIfNotHidden causes chaos

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • P2: Important
    • Some future release
    • 4.5.2
    • Widgets: Layout
    • None
    • Windows, Linux

    Description

      See attached code,
      If you:
      1 add a widget to a visible layout
      2 remove that widget
      3 set that widget's parent to NULL

      the widget will appear as a top level window, because in step 1, QLayout::addChildWidget() queues a call to QWidgetPrivate::_q_showIfNotHidden(), which calls setVisible(true) while the parent is NULL, hence the widget becomes a top level widget.

      The code explains the motivation for wanting to do it in the first place, the comments copy-pasted are:
      // The purpose of this code is to try and identify the correct way to:
      //
      // * Add a widget (A) to a visible layout (L), and then immediately remove it
      // * Delete the layout's widget-parent (P), and ensure widget-A is NOT deleted as if it were still a child of P.
      //

      // Approach 1 - do nothing special,
      // but this will result in a being destroyed

      // Approach 2 - set parent to NULL,
      // but this will result in a becoming a window of its own

      // Approach 3 - set parent to a QWidget that is never shown
      // this works but this solution was only discovered after diving into QT code, it is not obvious from reading the documentation

      Attachments

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

        Activity

          People

            smd Jan Arve
            elegant_dice Paul
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes