diff options
author | Thierry Bastian <thierry.bastian@nokia.com> | 2010-09-29 10:56:38 (GMT) |
---|---|---|
committer | Jason McDonald <jason.mcdonald@nokia.com> | 2010-10-04 06:36:04 (GMT) |
commit | acc1dc498ea733bab2a1f5ef9983829adbbf5735 (patch) | |
tree | 9b3907b7bde9d81dd83bb745f346562da8e0d5fa /tests/auto | |
parent | 6c53410d8104064b53beccb1f2014c980735aefb (diff) | |
download | Qt-acc1dc498ea733bab2a1f5ef9983829adbbf5735.zip Qt-acc1dc498ea733bab2a1f5ef9983829adbbf5735.tar.gz Qt-acc1dc498ea733bab2a1f5ef9983829adbbf5735.tar.bz2 |
Fix double painting when adding an item into a linear layout
the problem was that the item is first painted at its default position,
then moved by the layout and finally repainted.
We now made sure the item is laid out before the first paint event
occurs.
Task-number: QTBUG-13865
Reviewed-by: bnilsen
(cherry picked from commit 33f525e636ef8fa64a15d3e66c56adaea0075bda)
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp index ddc4f73..7f24ddc 100644 --- a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp +++ b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp @@ -184,6 +184,7 @@ private slots: void task250119_shortcutContext(); void QT_BUG_6544_tabFocusFirstUnsetWhenRemovingItems(); void QT_BUG_12056_tabFocusFirstUnsetWhenRemovingItems(); + void QT_BUG_13865_doublePaintWhenAddingASubItem(); }; @@ -3321,6 +3322,45 @@ void tst_QGraphicsWidget::QT_BUG_12056_tabFocusFirstUnsetWhenRemovingItems() //This should not crash } + +struct GreenWidget : public QGraphicsWidget +{ + GreenWidget() : count(0) + { + } + + void paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * ) + { + count++; + painter->setPen(Qt::green); + painter->drawRect(option->rect.adjusted(0,0,-1,-1)); + } + + int count; +}; + +void tst_QGraphicsWidget::QT_BUG_13865_doublePaintWhenAddingASubItem() +{ + QGraphicsScene scene; + QGraphicsView view(&scene); + QGraphicsWidget *widget = new QGraphicsWidget; + widget->resize(100, 100); + scene.addItem(widget); + QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(widget); + + view.show(); + QTest::qWaitForWindowShown(&view); + + + GreenWidget *sub = new GreenWidget; + layout->addItem(sub); + + QTest::qWait(100); + QCOMPARE(sub->count, 1); //it should only be painted once + +} + + QTEST_MAIN(tst_QGraphicsWidget) #include "tst_qgraphicswidget.moc" |