Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-76543

Disabled QAction with menu becomes enabled when enabling it's parent

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P2: Important P2: Important
    • None
    • 5.7.1, 5.11.2, 5.12.2
    • None
    • Windows 10
      Visual Studio 2015/2019
    • Windows

      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;
      }
      

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            avdovichenko Anton
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes