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

QToolButton::setDefaultAction should connect visibility as well

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3: Somewhat important P3: Somewhat important
    • None
    • 6.9
    • None

      QToolBar::addAction and QToolBar::addWidget are slightly different in that QAction::setVisible will:

      • Show/Hide the Button if added via QToolBar::addAction(QAction)
      • Enable/Disable the Button if added via QToolBar::addWidget(QToolButton)

      This distinction seems to make little sense to the user. 

      See the example:

      #include <QApplication>
      #include <QToolBar>
      #include <QMainWindow>
      #include <QToolButton>
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          QMainWindow mainWindow;
          QToolBar toolBar;
          mainWindow.setCentralWidget((QWidget*)&toolBar);
          QAction action;
          action.setText("Hello");
          QAction action2;
          action2.setText("World");
          QToolButton button;
          button.setDefaultAction(&action2);
          QObject::connect(&action, &QAction::triggered, &action, [&action]{
              action.setVisible(false);
          });
          QObject::connect(&action2, &QAction::triggered, &action2, [&action2]{
              action2.setVisible(false);
          });
          toolBar.addAction(&action);
          toolBar.addWidget(&button);
          mainWindow.show();
          return a.exec();
      }
       

      Clicking "Hello" will hide it, but clicking "World" will disable it.

        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
            madwinter Marcus Tillmanns
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes