From 5fc90f7a08873fa456cfa73752a50d9b4ad41812 Mon Sep 17 00:00:00 2001 From: baldurk Date: Fri, 16 Jun 2017 23:31:05 +0100 Subject: [PATCH] Fix menus not showing up on some user configurations * Menus aren't guaranteed to pass isVisible() immediately after calling popup() on them, so we need to wait for their aboutToHide signal to stop the event loop. --- qrenderdoc/Code/QRDUtils.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/qrenderdoc/Code/QRDUtils.cpp b/qrenderdoc/Code/QRDUtils.cpp index b9391cfd8..3f6d5d42a 100644 --- a/qrenderdoc/Code/QRDUtils.cpp +++ b/qrenderdoc/Code/QRDUtils.cpp @@ -24,6 +24,7 @@ #include "QRDUtils.h" #include +#include #include #include #include @@ -347,14 +348,35 @@ const QMessageBox::StandardButtons RDDialog::YesNoCancel = void RDDialog::show(QMenu *menu, QPoint pos) { + // menus aren't always visible immediately, so we need to listen for aboutToHide to exit the event + // loop. As a safety precaution because I don't trust the damn signals, if we loop for over a + // second then we'll quit as soon as the menu is not visible + volatile bool menuHiding = false; + auto connection = + QObject::connect(menu, &QMenu::aboutToHide, [&menuHiding]() { menuHiding = true; }); + menu->setWindowModality(Qt::ApplicationModal); menu->popup(pos); + + QElapsedTimer elapsed; + elapsed.start(); + QEventLoop loop; - while(menu->isVisible()) + for(;;) { + // stop processing once aboutToHide has been signalled + if(menuHiding) + break; + + // stop processing if 1s has passed and the menu isn't visible anymore. + if(elapsed.hasExpired(1000) && !menu->isVisible()) + break; + loop.processEvents(QEventLoop::WaitForMoreEvents); QCoreApplication::sendPostedEvents(); } + + QObject::disconnect(connection); } int RDDialog::show(QDialog *dialog)