Solved QWidgetAction on MacOS creates additional empty dialog windows when activated!?
-
Hi,
I am testing my first Qt app on MacOS 10.12, and again have some strange things happening that don't happen in Windows.I have several Menu items which are of the type
QWidgetAction
and which mostly contain aQComboBox
from which I can select preset values.I know that
QWidgetAction
comes with some restrictions on MacOS X, but that it should basically work.However, on MacOS, whenever I first activate such a
QWidgetAction
, a small, empty, translucent dialog box pops up which does not close, unless I click on the close button of that dialog. After I close the dialog, it does not reappear for that menu item. However, other menu items of the typeQWidgetAction
will still spawn such empty dialog windows. I can end up with several of these at the same time...Furthermore, at the second activation of such a
QComboBox
in aQWidgetAction
, the contents of the combo box only show when clicked upon; if not clicked, it only shows an empty rectangle.What is the correct way on MacOS X to add a combo box menu item to the main application menu, since QWidgetAction does not seem to work correctly?
-
Hi,
Please provide a minium compilable example that reproduces this behaviour.
-
@SGaist
Created Qt application, with single form and added QMenuSettings
to menubar via Qt Designer. Then, still in Qt Designer, added a submenumenuTest
to Settings.After this, the auto-generated
ui_mainwindow.h
file looks as follows:#ifndef UI_MAINWINDOW_H #define UI_MAINWINDOW_H #include <QtCore/QVariant> #include <QtWidgets/QAction> #include <QtWidgets/QApplication> #include <QtWidgets/QButtonGroup> #include <QtWidgets/QHeaderView> #include <QtWidgets/QMainWindow> #include <QtWidgets/QMenu> #include <QtWidgets/QMenuBar> #include <QtWidgets/QStatusBar> #include <QtWidgets/QToolBar> #include <QtWidgets/QWidget> QT_BEGIN_NAMESPACE class Ui_MainWindow { public: QAction *actionSub; QWidget *centralWidget; QMenuBar *menuBar; QMenu *menuSettings; QMenu *menuTest; QToolBar *mainToolBar; QStatusBar *statusBar; void setupUi(QMainWindow *MainWindow) { if (MainWindow->objectName().isEmpty()) MainWindow->setObjectName(QStringLiteral("MainWindow")); MainWindow->resize(400, 300); actionSub = new QAction(MainWindow); actionSub->setObjectName(QStringLiteral("actionSub")); centralWidget = new QWidget(MainWindow); centralWidget->setObjectName(QStringLiteral("centralWidget")); MainWindow->setCentralWidget(centralWidget); menuBar = new QMenuBar(MainWindow); menuBar->setObjectName(QStringLiteral("menuBar")); menuBar->setGeometry(QRect(0, 0, 400, 22)); menuSettings = new QMenu(menuBar); menuSettings->setObjectName(QStringLiteral("menuSettings")); menuTest = new QMenu(menuSettings); menuTest->setObjectName(QStringLiteral("menuTest")); MainWindow->setMenuBar(menuBar); mainToolBar = new QToolBar(MainWindow); mainToolBar->setObjectName(QStringLiteral("mainToolBar")); MainWindow->addToolBar(Qt::TopToolBarArea, mainToolBar); statusBar = new QStatusBar(MainWindow); statusBar->setObjectName(QStringLiteral("statusBar")); MainWindow->setStatusBar(statusBar); menuBar->addAction(menuSettings->menuAction()); menuSettings->addAction(menuTest->menuAction()); retranslateUi(MainWindow); QMetaObject::connectSlotsByName(MainWindow); } // setupUi void retranslateUi(QMainWindow *MainWindow) { MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", Q_NULLPTR)); actionSub->setText(QApplication::translate("MainWindow", "Sub", Q_NULLPTR)); menuSettings->setTitle(QApplication::translate("MainWindow", "Settings", Q_NULLPTR)); menuTest->setTitle(QApplication::translate("MainWindow", "Test", Q_NULLPTR)); } // retranslateUi }; namespace Ui { class MainWindow: public Ui_MainWindow {}; } // namespace Ui QT_END_NAMESPACE #endif // UI_MAINWINDOW_H
From this point on:
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QComboBox> namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); private: Ui::MainWindow *ui; QComboBox* m_testComboBox; }; #endif // MAINWINDOW_H
The source file:
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QWidgetAction> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); m_testComboBox = new QComboBox(ui->menuTest); for (int i=0; i<10; ++i) m_testComboBox->addItem(QString::number(i), QVariant(i)); QWidgetAction* testAction = new QWidgetAction(ui->menuTest); testAction->setDefaultWidget(m_testComboBox); ui->menuTest->addAction(testAction); } MainWindow::~MainWindow() { delete ui; }
Result:
The ghost dialog window is spawned when the Test submenu is activated (combobox not yet triggered).The contents of the QComboBox only appear when clicked on it + shows an empty rectangle behinds it.
I realize the Qt Framework is an extremly complex and large undertaking, but these sorts of things are a little bit tiring, for an unskilled amateur programmer like myself...
Of course, I cannot rule out that all these problems (there are others, but this one seems to be a pure GUI issue rather than HW related such as Audio or Mouse) I am facing with porting to MacOS X may be due to the fact that I am using a VM rather than a physical MacOS machine... -
I confirm, it's completly buggy on Mac (10.9.5 for me) and unusable.
I don't see any ghost window though. -
@mpergand said in QWidgetAction on MacOS creates additional empty dialog windows when activated!?:
I don't see any ghost window though.
Are you using a MacOS X Virtual Machine (mine is VMware Player)?
-
@Diracsbracket said in QWidgetAction on MacOS creates additional empty dialog windows when activated!?:
Are you using a MacOS X Virtual Machine (mine is VMware Player)?
No, it's a real Mac.
Anyway, i don"t see any advantage of a combo over a list of menu items here.
To avoid possible issues, it's advisable to do simplest things as much as possible. (in particular if you're targeting MacOS) IMHO -
I'm not getting any ghost Windows with my Qt 5.10 build on macOS 10.12.6 however there are some focus issue.
In any case, I agree with @mpergand a combo box is pretty unusual in an application menu. A checkable action is more likely to be in the user expectation.
-
This post is deleted! -
This post is deleted! -
@mpergand said in QWidgetAction on MacOS creates additional empty dialog windows when activated!?:
To avoid possible issues, it's advisable to do simplest things as much as possible. (in particular if you're targeting MacOS) IMHO
Hi,
Since theQWidgetAction
did definitely not work correctly on MacOS X (although Qt 5.10 has an improvement as @SGaist mentioned), I heeded your advice and spent the day replacing all theQWidgetActions
byQActions
in aQActionGroup
, and I must say, it looks much better. More importantly, it works on both Windows and MacOS X.Cheers!
Although the original issues of ghost windows et al. are not really solved, at least on Qt 5.9.4, I will put this question as solved nonetheless. The answer is simply: don't use
QActionWidget
in the application menu.