-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.7.1, 5.11.2, 5.12.2
-
None
-
Windows 10
Visual Studio 2015/2019
If the QAction which has a menu has been set disabled, it erroneously enabled when it's parent becomes enabled. There is no such issue for QAction without menu.
There is the sample code showing the issue:
#include <QApplication> #include <QMainWindow> #include <QMenu> #include <QToolBar> class MainWindow : public QMainWindow { public: MainWindow() : QMainWindow() { QToolBar* toolBar = new QToolBar(this); QAction* actionWithMenu = new QAction("Action with menu", this); QMenu* menu = new QMenu(this); QAction* menuAction = new QAction("Menu action", this); menu->addAction(menuAction); actionWithMenu->setMenu(menu); QAction* actionWithoutMenu = new QAction("Action without menu", this); toolBar->addAction(actionWithMenu); toolBar->addAction(actionWithoutMenu); actionWithMenu->setEnabled(false); actionWithoutMenu->setEnabled(false); addToolBar(toolBar); setEnabled(false); setEnabled(true); // this line causes the issue } protected: QSize sizeHint() const Q_DECL_OVERRIDE { return QSize(640, 480); } }; int main(int argc, char *argv[]) { QApplication a(argc, argv); QMainWindow* window = new MainWindow(); window->show(); a.exec(); return 0; }