summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@nokia.com>2010-09-27 15:35:06 (GMT)
committerFrederik Gladhorn <frederik.gladhorn@nokia.com>2010-10-01 12:04:40 (GMT)
commitc146652bfb336c084c39db7513e27540e456791e (patch)
tree1f5eb1921eb86029723900e76aef6f64b0f3b497 /tests
parentc6398b785588486c5fc52cb1d71000c0815d995e (diff)
downloadQt-c146652bfb336c084c39db7513e27540e456791e.zip
Qt-c146652bfb336c084c39db7513e27540e456791e.tar.gz
Qt-c146652bfb336c084c39db7513e27540e456791e.tar.bz2
FocusOut even when QGraphicsItem gets hidden.
If a parent QGraphicsItem becomes invisible, its child would not receive a focus out event. Review-by: Thierry Task-number: QTBUG-13916
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp
index 5891075..9d6def8 100644
--- a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp
+++ b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp
@@ -101,6 +101,7 @@ private slots:
void focusWidget_data();
void focusWidget();
void focusWidget2();
+ void focusWidget3();
void focusPolicy_data();
void focusPolicy();
void font_data();
@@ -558,6 +559,39 @@ void tst_QGraphicsWidget::focusWidget2()
QVERIFY(!widget->focusWidget());
}
+class FocusWatchWidget : public QGraphicsWidget
+{
+public:
+ FocusWatchWidget(QGraphicsItem *parent = 0) : QGraphicsWidget(parent) { gotFocusInCount = 0; gotFocusOutCount = 0; }
+ int gotFocusInCount, gotFocusOutCount;
+protected:
+ void focusInEvent(QFocusEvent *fe) { gotFocusInCount++; QGraphicsWidget::focusInEvent(fe); }
+ void focusOutEvent(QFocusEvent *fe) { gotFocusOutCount++; QGraphicsWidget::focusOutEvent(fe); }
+};
+
+void tst_QGraphicsWidget::focusWidget3()
+{
+ QGraphicsScene scene;
+ QEvent windowActivate(QEvent::WindowActivate);
+ qApp->sendEvent(&scene, &windowActivate);
+
+ QGraphicsWidget *widget = new QGraphicsWidget;
+ FocusWatchWidget *subWidget = new FocusWatchWidget(widget);
+ subWidget->setFocusPolicy(Qt::StrongFocus);
+
+ scene.addItem(widget);
+ widget->show();
+
+ QTRY_VERIFY(!widget->hasFocus());
+ QTRY_VERIFY(!subWidget->hasFocus());
+
+ subWidget->setFocus();
+ QCOMPARE(subWidget->gotFocusInCount, 1);
+ QCOMPARE(subWidget->gotFocusOutCount, 0);
+ widget->hide();
+ QCOMPARE(subWidget->gotFocusOutCount, 1);
+}
+
Q_DECLARE_METATYPE(Qt::FocusPolicy)
void tst_QGraphicsWidget::focusPolicy_data()
{