Important: Please read the Qt Code of Conduct -

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 a QComboBox 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 type QWidgetAction will still spawn such empty dialog windows. I can end up with several of these at the same time...

    0_1517742686598_MacOS X QWidgetAction.png

    Furthermore, at the second activation of such a QComboBox in a QWidgetAction, the contents of the combo box only show when clicked upon; if not clicked, it only shows an empty rectangle.

    0_1517742702373_MacOS X QWidgetAction Empty.png

    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?

  • Lifetime Qt Champion


    Please provide a minium compilable example that reproduces this behaviour.

  • @SGaist
    Created Qt application, with single form and added QMenu Settings to menubar via Qt Designer. Then, still in Qt Designer, added a submenu menuTest 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>
    class Ui_MainWindow
        QAction *actionSub;
        QWidget *centralWidget;
        QMenuBar *menuBar;
        QMenu *menuSettings;
        QMenu *menuTest;
        QToolBar *mainToolBar;
        QStatusBar *statusBar;
        void setupUi(QMainWindow *MainWindow)
            if (MainWindow->objectName().isEmpty())
            MainWindow->resize(400, 300);
            actionSub = new QAction(MainWindow);
            centralWidget = new QWidget(MainWindow);
            menuBar = new QMenuBar(MainWindow);
            menuBar->setGeometry(QRect(0, 0, 400, 22));
            menuSettings = new QMenu(menuBar);
            menuTest = new QMenu(menuSettings);
            mainToolBar = new QToolBar(MainWindow);
            MainWindow->addToolBar(Qt::TopToolBarArea, mainToolBar);
            statusBar = new QStatusBar(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
    #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
        explicit MainWindow(QWidget *parent = 0);
        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) :
        ui(new Ui::MainWindow)
        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);
        delete ui;

    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.
    0_1517844303198_WidgetAction bug.png
    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

  • Lifetime Qt Champion

    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

    Since the QWidgetAction 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 the QWidgetActions by QActions in a QActionGroup, and I must say, it looks much better. More importantly, it works on both Windows and MacOS X.

    Cheers!0_1518047993651_Screen Shot 2018-02-07 at 3.58.04 PM.png

    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.

Log in to reply