summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--src/gui/graphicsview/qgraphicsitem.cpp8
-rw-r--r--tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp34
2 files changed, 39 insertions, 3 deletions
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp
index 3b18c31..fc44a44 100644
--- a/src/gui/graphicsview/qgraphicsitem.cpp
+++ b/src/gui/graphicsview/qgraphicsitem.cpp
@@ -6655,6 +6655,11 @@ bool QGraphicsItem::sceneEvent(QEvent *event)
return true;
}
+ if (event->type() == QEvent::FocusOut) {
+ focusOutEvent(static_cast<QFocusEvent *>(event));
+ return true;
+ }
+
if (!d_ptr->visible) {
// Eaten
return true;
@@ -6664,9 +6669,6 @@ bool QGraphicsItem::sceneEvent(QEvent *event)
case QEvent::FocusIn:
focusInEvent(static_cast<QFocusEvent *>(event));
break;
- case QEvent::FocusOut:
- focusOutEvent(static_cast<QFocusEvent *>(event));
- break;
case QEvent::GraphicsSceneContextMenu:
contextMenuEvent(static_cast<QGraphicsSceneContextMenuEvent *>(event));
break;
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()
{