From bf200fc948d89e1a735a8bcca879654028f944d2 Mon Sep 17 00:00:00 2001 From: Jan Arve Saether Date: Mon, 20 Oct 2014 15:40:18 +0200 Subject: Adjust the layout if a QGraphicsWidget is explicitly hidden Since layout items can now be hidden, this also makes sure we respect the QSizePolicy::retainSizeWhenHidden Task-number: QTBUG-20132 Change-Id: Iab59fc9b61d4ca1bb2208c479a027da6eb0283a9 Reviewed-by: Paul Olav Tvete --- .../graphicsview/qgraphicsgridlayoutengine.cpp | 20 ++++++++++++++++++++ .../graphicsview/qgraphicsgridlayoutengine_p.h | 4 ++++ src/widgets/graphicsview/qgraphicswidget.cpp | 4 ++++ 3 files changed, 28 insertions(+) (limited to 'src/widgets/graphicsview') diff --git a/src/widgets/graphicsview/qgraphicsgridlayoutengine.cpp b/src/widgets/graphicsview/qgraphicsgridlayoutengine.cpp index 3d9c5d6de5..c9b2ecd62c 100644 --- a/src/widgets/graphicsview/qgraphicsgridlayoutengine.cpp +++ b/src/widgets/graphicsview/qgraphicsgridlayoutengine.cpp @@ -38,9 +38,29 @@ #include "qgraphicslayoutitem_p.h" #include "qgraphicslayout_p.h" #include "qgraphicswidget.h" +#include QT_BEGIN_NAMESPACE +bool QGraphicsGridLayoutEngineItem::isHidden() const +{ + if (QGraphicsItem *item = q_layoutItem->graphicsItem()) + return QGraphicsItemPrivate::get(item)->explicitlyHidden; + return false; +} + +/*! + \internal + + If this returns true, the layout will arrange just as if the item was never added to the layout. + (Note that this shouldn't lead to a "double spacing" where the item was hidden) + ### Qt6: Move to QGraphicsLayoutItem and make virtual +*/ +bool QGraphicsGridLayoutEngineItem::isIgnored() const +{ + return isHidden() && !q_layoutItem->sizePolicy().retainSizeWhenHidden(); +} + /* returns \c true if the size policy returns \c true for either hasHeightForWidth() or hasWidthForHeight() diff --git a/src/widgets/graphicsview/qgraphicsgridlayoutengine_p.h b/src/widgets/graphicsview/qgraphicsgridlayoutengine_p.h index 4d6bdfce0a..07486514f8 100644 --- a/src/widgets/graphicsview/qgraphicsgridlayoutengine_p.h +++ b/src/widgets/graphicsview/qgraphicsgridlayoutengine_p.h @@ -82,6 +82,10 @@ public: return q_layoutItem->effectiveSizeHint(which, constraint); } + bool isHidden() const; + + virtual bool isIgnored() const Q_DECL_OVERRIDE; + virtual void setGeometry(const QRectF &rect) Q_DECL_OVERRIDE { q_layoutItem->setGeometry(rect); diff --git a/src/widgets/graphicsview/qgraphicswidget.cpp b/src/widgets/graphicsview/qgraphicswidget.cpp index 4a9c3b098e..5bd563e535 100644 --- a/src/widgets/graphicsview/qgraphicswidget.cpp +++ b/src/widgets/graphicsview/qgraphicswidget.cpp @@ -1137,6 +1137,10 @@ QVariant QGraphicsWidget::itemChange(GraphicsItemChange change, const QVariant & setAttribute(Qt::WA_Resized, false); } } + + // layout size hint only changes if an item changes from/to explicitly hidden state + if (value.toBool() || d->explicitlyHidden) + updateGeometry(); break; case ItemVisibleHasChanged: if (!value.toBool()) { -- cgit v1.2.3