[Interest] Menu causes problems on OS X

John Weeks john at wavemetrics.com
Tue May 10 20:51:49 CEST 2016


The very simple application posted below (it is a complete runnable example) creates a window that puts up a menu on clicking in the window. If you select "Open File..." it then puts up a QFileDialog to choose a file. Upon returning, the window no longer appears to active. Experience with our real application where we observe this behavior suggests that Qt thinks the window is still active, but OS X does not. This causes other strange problems.

Application works as expected on Windows.

I am inclined to believe this is a Qt bug. But I would be interested to know what others think, and if you might know of a work-around.

Thanks!

-John Weeks

#include <QApplication>
#include <QMainWindow>
#include <QMouseEvent>
#include <QFileDialog>
#include <QString>
#include <QDebug>
#include <QMenu>
#include <QAction>

class MainWindow : public QMainWindow
{
	public:
		explicit MainWindow(QWidget *parent = 0);
		~MainWindow();

	protected:
		void	mouseReleaseEvent(QMouseEvent * event);

	private:
};

MainWindow::MainWindow(QWidget *parent) :
	QMainWindow(parent)
{
}

MainWindow::~MainWindow()
{
}

void MainWindow::mouseReleaseEvent(QMouseEvent * event)
{
	QMenu menu;
	menu.addAction("Open File...");
	QAction * selectedAction = menu.exec(event->globalPos());

	if (selectedAction)
	{
		QFileDialog::Options options = 0;
		// options |= QFileDialog::DontUseNativeDialog;
		QString fullQtPath = QFileDialog::getOpenFileName(NULL, QStringLiteral("Dialog Caption"), QString(), QString(), nullptr, options);
		qDebug() << fullQtPath;
	}
}

int main(int argc, char *argv[])
{
	QApplication a(argc, argv);
	MainWindow w;
	w.show();

	return a.exec();
}





More information about the Interest mailing list