Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.8.2, 6.8.3
-
None
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.