From 27fa02e29d873db4fdf1e77feee600f1e15e94f4 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 28 Mar 2014 10:43:53 +0100 Subject: tst_qgraphicsproxywidget: Fix hang in actionsContextMenu(). Change the test widget to use a non-single-shot timer to hide the menu once it has become visible. The test shows hangs on Windows 8.1 CI nodes. Task-number: QTBUG-37822 Change-Id: I8fc782e53256616119920aef714f89f25863b39f Reviewed-by: Oliver Wolff --- .../tst_qgraphicsproxywidget.cpp | 41 ++++++++++++++++------ 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp index d3f6c2db00..5b178903cf 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp @@ -3065,21 +3065,30 @@ void tst_QGraphicsProxyWidget::createProxyForChildWidget() delete boxProxy; } -class ContextMenuWidget : public QWidget +class ContextMenuWidget : public QLabel { Q_OBJECT public: ContextMenuWidget() - : embeddedPopup(false), - gotContextMenuEvent(false) + : QLabel(QStringLiteral("ContextMenuWidget")) + , embeddedPopup(false) + , gotContextMenuEvent(false) + , m_embeddedPopupSet(false) + , m_timer(0) { } bool embeddedPopup; bool gotContextMenuEvent; protected: bool event(QEvent *event) { - if (event->type() == QEvent::ContextMenu) - QTimer::singleShot(0, this, SLOT(checkMenu())); + if (event->type() == QEvent::ContextMenu) { + if (!m_timer) { + m_timer = new QTimer(this); + m_timer->setInterval(10); + connect(m_timer, SIGNAL(timeout()), this, SLOT(checkMenu())); + m_timer->start(); + } + } return QWidget::event(event); } void contextMenuEvent(QContextMenuEvent *) @@ -3090,10 +3099,19 @@ protected: private slots: void checkMenu() { - if (this->findChild()) - embeddedPopup = true; + QMenu *menu = findChild(); + if (!m_embeddedPopupSet) { + m_embeddedPopupSet = true; + embeddedPopup = menu != 0; + } + if (menu && menu->isVisible()) + menu->hide(); hide(); } + +private: + bool m_embeddedPopupSet; + QTimer *m_timer; }; void tst_QGraphicsProxyWidget::actionsContextMenu_data() @@ -3120,8 +3138,11 @@ void tst_QGraphicsProxyWidget::actionsContextMenu() widget->setContextMenuPolicy(Qt::ActionsContextMenu); } QGraphicsScene scene; - + QGraphicsProxyWidget *proxyWidget = scene.addWidget(widget); QGraphicsView view(&scene); + view.setWindowTitle(QStringLiteral("actionsContextMenu")); + view.resize(200, 200); + view.move(QGuiApplication::primaryScreen()->geometry().center() - QPoint(100, 100)); view.show(); QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); @@ -3129,9 +3150,9 @@ void tst_QGraphicsProxyWidget::actionsContextMenu() QTRY_VERIFY(view.hasFocus()); if (hasFocus) - scene.addWidget(widget)->setFocus(); + proxyWidget->setFocus(); else - scene.addWidget(widget)->clearFocus(); + proxyWidget->clearFocus(); QApplication::processEvents(); -- cgit v1.2.3