From ccd3bf0871b81dfc09bb469b161f32dfb47ee53e Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Tue, 22 Oct 2019 13:01:38 +0200 Subject: Ensure that child windows are visible again when showing their parent When a window is closed, then it will cause the child windows to be closed as well as a result. Therefore in order to ensure that they are shown again as a result, we need to remove the WA_WState_ExplicitShowHide attribute if the widget was not already hidden before. This enables us to test for this attribute when calling showChildren(), so that if the window has a windowHandle then we can make sure that this widget is shown again. Fixes: QTBUG-73021 Change-Id: I1186242b889899dfcd38d782a67567348e2055ee Reviewed-by: Ulf Hermann --- src/widgets/kernel/qwidget.cpp | 4 +++- src/widgets/kernel/qwidgetwindow.cpp | 12 ++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 0fa5907744..048a17364b 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -1,4 +1,4 @@ -/**************************************************************************** +/**************************************************************************** ** ** Copyright (C) 2017 The Qt Company Ltd. ** Copyright (C) 2016 Intel Corporation. @@ -8460,6 +8460,8 @@ void QWidgetPrivate::showChildren(bool spontaneous) QList childList = children; for (int i = 0; i < childList.size(); ++i) { QWidget *widget = qobject_cast(childList.at(i)); + if (widget && widget->windowHandle() && !widget->testAttribute(Qt::WA_WState_ExplicitShowHide)) + widget->setAttribute(Qt::WA_WState_Hidden, false); if (!widget || widget->isWindow() || widget->testAttribute(Qt::WA_WState_Hidden)) diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp index aad505ed29..878e484ab8 100644 --- a/src/widgets/kernel/qwidgetwindow.cpp +++ b/src/widgets/kernel/qwidgetwindow.cpp @@ -72,10 +72,18 @@ public: void setVisible(bool visible) override { Q_Q(QWidgetWindow); - if (QWidget *widget = q->widget()) + if (QWidget *widget = q->widget()) { + // Check if the widget was already hidden, as this indicates it was done + // explicitly and not because the parent window in this case made it hidden. + // In which case do not automatically show the widget when the parent + // window is shown. + const bool wasHidden = widget->testAttribute(Qt::WA_WState_Hidden); QWidgetPrivate::get(widget)->setVisible(visible); - else + if (!wasHidden) + widget->setAttribute(Qt::WA_WState_ExplicitShowHide, false); + } else { QWindowPrivate::setVisible(visible); + } } QWindow *eventReceiver() override { -- cgit v1.2.3 From f54e97726f36c56d9f51f2243493c55ab8cf7bef Mon Sep 17 00:00:00 2001 From: Leena Miettinen Date: Wed, 30 Oct 2019 10:50:41 +0100 Subject: Doc: Add notes about Qt Style Sheets taking precedence ...over setting properties on individual widgets. Task-number: QTBUG-28675 Change-Id: Ic7bfd723ed8970112a9892727170d3bacaa1903f Reviewed-by: Frederik Gladhorn --- src/widgets/doc/src/widgets-and-layouts/stylesheet.qdoc | 7 ++++++- src/widgets/itemviews/qtreewidget.cpp | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/doc/src/widgets-and-layouts/stylesheet.qdoc b/src/widgets/doc/src/widgets-and-layouts/stylesheet.qdoc index 00323eace6..12e27a71ad 100644 --- a/src/widgets/doc/src/widgets-and-layouts/stylesheet.qdoc +++ b/src/widgets/doc/src/widgets-and-layouts/stylesheet.qdoc @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the documentation of the Qt Toolkit. @@ -59,6 +59,11 @@ \li \l{Qt Style Sheets Examples} \endlist + \note If Qt Style Sheets are used on the same widget as functions that + set the appearance of widgets, such as \l QWidget::setFont() or + \l QTreeWidgetItem::setBackground(), style sheets will take precedence + if the settings conflict. + \target overview \section1 Overview diff --git a/src/widgets/itemviews/qtreewidget.cpp b/src/widgets/itemviews/qtreewidget.cpp index be7ddd8b30..6da5ca0f4c 100644 --- a/src/widgets/itemviews/qtreewidget.cpp +++ b/src/widgets/itemviews/qtreewidget.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtWidgets module of the Qt Toolkit. @@ -1284,6 +1284,9 @@ bool QTreeWidgetItem::isFirstColumnSpanned() const Sets the background brush of the label in the given \a column to the specified \a brush. + \note If \l{Qt Style Sheets} are used on the same widget as setBackground(), + style sheets will take precedence if the settings conflict. + \sa setForeground() */ -- cgit v1.2.3