diff options
author | Jan Arve Saether <jan-arve.saether@theqtcompany.com> | 2014-10-20 15:40:18 +0200 |
---|---|---|
committer | Jan Arve Sæther <jan-arve.saether@theqtcompany.com> | 2014-10-23 07:17:50 +0200 |
commit | bf200fc948d89e1a735a8bcca879654028f944d2 (patch) | |
tree | 2696c1a5314d722100a28f1b44ff54aa5f1e803e /src/widgets | |
parent | e5c1572e7eafbce26ca5835c7fe1682bfb69d92b (diff) | |
download | qtbase-bf200fc948d89e1a735a8bcca879654028f944d2.tar.gz |
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 <paul.tvete@digia.com>
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/graphicsview/qgraphicsgridlayoutengine.cpp | 20 | ||||
-rw-r--r-- | src/widgets/graphicsview/qgraphicsgridlayoutengine_p.h | 4 | ||||
-rw-r--r-- | src/widgets/graphicsview/qgraphicswidget.cpp | 4 |
3 files changed, 28 insertions, 0 deletions
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 <private/qgraphicswidget_p.h> 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()) { |