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 <oliver.wolff@digia.com>
This commit is contained in:
parent
b980df3f3c
commit
27fa02e29d
@ -3065,21 +3065,30 @@ void tst_QGraphicsProxyWidget::createProxyForChildWidget()
|
|||||||
delete boxProxy;
|
delete boxProxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ContextMenuWidget : public QWidget
|
class ContextMenuWidget : public QLabel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
ContextMenuWidget()
|
ContextMenuWidget()
|
||||||
: embeddedPopup(false),
|
: QLabel(QStringLiteral("ContextMenuWidget"))
|
||||||
gotContextMenuEvent(false)
|
, embeddedPopup(false)
|
||||||
|
, gotContextMenuEvent(false)
|
||||||
|
, m_embeddedPopupSet(false)
|
||||||
|
, m_timer(0)
|
||||||
{ }
|
{ }
|
||||||
bool embeddedPopup;
|
bool embeddedPopup;
|
||||||
bool gotContextMenuEvent;
|
bool gotContextMenuEvent;
|
||||||
protected:
|
protected:
|
||||||
bool event(QEvent *event)
|
bool event(QEvent *event)
|
||||||
{
|
{
|
||||||
if (event->type() == QEvent::ContextMenu)
|
if (event->type() == QEvent::ContextMenu) {
|
||||||
QTimer::singleShot(0, this, SLOT(checkMenu()));
|
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);
|
return QWidget::event(event);
|
||||||
}
|
}
|
||||||
void contextMenuEvent(QContextMenuEvent *)
|
void contextMenuEvent(QContextMenuEvent *)
|
||||||
@ -3090,10 +3099,19 @@ protected:
|
|||||||
private slots:
|
private slots:
|
||||||
void checkMenu()
|
void checkMenu()
|
||||||
{
|
{
|
||||||
if (this->findChild<QMenu *>())
|
QMenu *menu = findChild<QMenu *>();
|
||||||
embeddedPopup = true;
|
if (!m_embeddedPopupSet) {
|
||||||
|
m_embeddedPopupSet = true;
|
||||||
|
embeddedPopup = menu != 0;
|
||||||
|
}
|
||||||
|
if (menu && menu->isVisible())
|
||||||
|
menu->hide();
|
||||||
hide();
|
hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_embeddedPopupSet;
|
||||||
|
QTimer *m_timer;
|
||||||
};
|
};
|
||||||
|
|
||||||
void tst_QGraphicsProxyWidget::actionsContextMenu_data()
|
void tst_QGraphicsProxyWidget::actionsContextMenu_data()
|
||||||
@ -3120,8 +3138,11 @@ void tst_QGraphicsProxyWidget::actionsContextMenu()
|
|||||||
widget->setContextMenuPolicy(Qt::ActionsContextMenu);
|
widget->setContextMenuPolicy(Qt::ActionsContextMenu);
|
||||||
}
|
}
|
||||||
QGraphicsScene scene;
|
QGraphicsScene scene;
|
||||||
|
QGraphicsProxyWidget *proxyWidget = scene.addWidget(widget);
|
||||||
QGraphicsView view(&scene);
|
QGraphicsView view(&scene);
|
||||||
|
view.setWindowTitle(QStringLiteral("actionsContextMenu"));
|
||||||
|
view.resize(200, 200);
|
||||||
|
view.move(QGuiApplication::primaryScreen()->geometry().center() - QPoint(100, 100));
|
||||||
view.show();
|
view.show();
|
||||||
QApplication::setActiveWindow(&view);
|
QApplication::setActiveWindow(&view);
|
||||||
QVERIFY(QTest::qWaitForWindowActive(&view));
|
QVERIFY(QTest::qWaitForWindowActive(&view));
|
||||||
@ -3129,9 +3150,9 @@ void tst_QGraphicsProxyWidget::actionsContextMenu()
|
|||||||
QTRY_VERIFY(view.hasFocus());
|
QTRY_VERIFY(view.hasFocus());
|
||||||
|
|
||||||
if (hasFocus)
|
if (hasFocus)
|
||||||
scene.addWidget(widget)->setFocus();
|
proxyWidget->setFocus();
|
||||||
else
|
else
|
||||||
scene.addWidget(widget)->clearFocus();
|
proxyWidget->clearFocus();
|
||||||
|
|
||||||
QApplication::processEvents();
|
QApplication::processEvents();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user