diff options
author | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2009-06-02 12:59:17 (GMT) |
---|---|---|
committer | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2009-06-02 14:19:04 (GMT) |
commit | 1a7da7096bbda17197738061902f4489af234bc0 (patch) | |
tree | db11d318edda713149ae67e1a4886da8dec51ac2 /tests | |
parent | 3be8bd20537ea215c7accaf1be3ffb6673fd897b (diff) | |
download | Qt-1a7da7096bbda17197738061902f4489af234bc0.zip Qt-1a7da7096bbda17197738061902f4489af234bc0.tar.gz Qt-1a7da7096bbda17197738061902f4489af234bc0.tar.bz2 |
Setting a focus on a widget hierarchy which contains both visible and
invisible widgets could cause a crash.
Also, when there is a widget hierarchy A->B->C and A and C are marked
as visible but B is hidden, when the user gives focus explicitely to
C, we should remember that and respect it when B becomes visible.
Task-number: 254563
Reviewed-by: Thierry Bastian
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qwidget/tst_qwidget.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/auto/qwidget/tst_qwidget.cpp b/tests/auto/qwidget/tst_qwidget.cpp index 23ead01..3fad366 100644 --- a/tests/auto/qwidget/tst_qwidget.cpp +++ b/tests/auto/qwidget/tst_qwidget.cpp @@ -350,6 +350,9 @@ private slots: void updateOnDestroyedSignal(); void toplevelLineEditFocus(); + void focusWidget_task254563(); + void focusWidget_mixed_widget_hierarchy(); + private: bool ensureScreenSize(int width, int height); QWidget *testWidget; @@ -8977,5 +8980,37 @@ void tst_QWidget::toplevelLineEditFocus() QCOMPARE(QApplication::focusWidget(), &w); } +void tst_QWidget::focusWidget_task254563() +{ + //having different visibility for widget is important + QWidget top; + top.show(); + QWidget container(&top); + QWidget *widget = new QWidget(&container); + widget->show(); + + widget->setFocus(); //set focus (will set the focus widget up to the toplevel to be 'widget') + container.setFocus(); + delete widget; // will call clearFocus but that doesn't help + QVERIFY(top.focusWidget() != widget); //dangling pointer +} + +void tst_QWidget::focusWidget_mixed_widget_hierarchy() +{ + QWidget top; + top.show(); + QWidget notvisible(&top); + QWidget *visible = new QWidget(¬visible); + visible->show(); + + visible->setFocus(); + notvisible.setFocus(); + notvisible.show(); + QCOMPARE(top.focusWidget(), visible); + QCOMPARE(notvisible.focusWidget(), visible); + QCOMPARE(visible->focusWidget(), visible); +} + + QTEST_MAIN(tst_QWidget) #include "tst_qwidget.moc" |