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

QToolButton popup menu not showing up if initially empty

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.8.2, 6.8.3
    • None
    • macOS, Windows

    Description

      The menu of a QToolButton does not show up if the menu is initially empty. Entries added later do not make the QMenu show up.

      Using the signal QMenu::aboutToShow shows that the menu is indeed not visible (menu->isVisible is false).

      Use this code in a QMainWindow to demonstrate the behaviour.

          QVBoxLayout* layout = new QVBoxLayout;
      
          QToolButton* btn = new QToolButton;
          btn->setPopupMode(QToolButton::InstantPopup);
      
          QMenu* menu = new QMenu;
          connect(menu, &QMenu::aboutToShow,
                  this, [this, menu]()
          {
              QTimer::singleShot(0, this, [menu](){
                   menu->addAction(QString("Entry %1").arg(menu->actions().size()));
                   qDebug() << "visible:" << menu->isVisible();
               });
          });
      
          // if the menu already has an entry it will show
          // menu->addAction("Entry 0");
      
          btn->setMenu(menu);
      
          layout->addWidget(btn);
      
          QWidget* w = new QWidget;
          w->setLayout(layout);
          setCentralWidget(w);

      This code works well with Qt 6.8.1 on macos and Windows.

      Attachments

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

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            i.n.g.o. Ingo Randolf
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes