From 290f002186497e3061a973c094e3f2aba6bd6aef Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Thu, 28 Jan 2010 15:43:12 +0100 Subject: Fixes missing update when setting opacity on an item that had opacity 0.0 We need to set the paintedViewBoundingRectsNeedRepaint flag when an item becomes visible again because when the item has opacity 0.0 the paintedViewBoundingRects struct can get set as outside of viewport, so the next time the item is set to visible again we need to diregard this cached data (otherwise the item will not be updated). Task-number: QTBUG-7714 Reviewed-by: bnilsen (cherry picked from commit 37f1aec1a4e71a7102e8cd2e2908c8d3be7e29f5) --- src/gui/graphicsview/qgraphicsitem.cpp | 3 ++ tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp | 39 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index e23e79b..08c3158 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -2568,6 +2568,7 @@ void QGraphicsItem::setOpacity(qreal opacity) if (newOpacity == d_ptr->opacity) return; + bool wasFullyTransparent = d_ptr->isOpacityNull(); d_ptr->opacity = newOpacity; // Notify change. @@ -2584,6 +2585,8 @@ void QGraphicsItem::setOpacity(qreal opacity) /*invalidateChildren=*/true, /*force=*/false, /*ignoreOpacity=*/d_ptr->isOpacityNull()); + if (wasFullyTransparent) + d_ptr->paintedViewBoundingRectsNeedRepaint = 1; } if (d_ptr->isObject) diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp index 9f68a1f..82bc5dd 100644 --- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp @@ -419,6 +419,7 @@ private slots: void QTBUG_4233_updateCachedWithSceneRect(); void QTBUG_5418_textItemSetDefaultColor(); void QTBUG_6738_missingUpdateWithSetParent(); + void QTBUG_7714_fullUpdateDiscardingOpacityUpdate2(); void QT_2653_fullUpdateDiscardingOpacityUpdate(); private: @@ -9995,5 +9996,43 @@ void tst_QGraphicsItem::QT_2653_fullUpdateDiscardingOpacityUpdate() QTRY_COMPARE(childYellow->repaints, 1); } +void tst_QGraphicsItem::QTBUG_7714_fullUpdateDiscardingOpacityUpdate2() +{ + QGraphicsScene scene(0, 0, 200, 200); + MyGraphicsView view(&scene); + MyGraphicsView origView(&scene); + + EventTester *parentGreen = new EventTester(); + parentGreen->setGeometry(QRectF(20, 20, 100, 100)); + parentGreen->brush = Qt::green; + + EventTester *childYellow = new EventTester(parentGreen); + childYellow->setGeometry(QRectF(10, 10, 50, 50)); + childYellow->brush = Qt::yellow; + + scene.addItem(parentGreen); + + origView.show(); + QTest::qWaitForWindowShown(&origView); + + parentGreen->setFlag(QGraphicsItem::ItemIgnoresTransformations); + + origView.reset(); + childYellow->setOpacity(0.0); + + QTRY_COMPARE(origView.repaints, 1); + + view.show(); + + QTest::qWaitForWindowShown(&view); + view.reset(); + origView.reset(); + + childYellow->setOpacity(1.0); + + QTRY_COMPARE(origView.repaints, 1); + QTRY_COMPARE(view.repaints, 1); +} + QTEST_MAIN(tst_QGraphicsItem) #include "tst_qgraphicsitem.moc" -- cgit v0.12