#include int main(int argc, char *argv[]) { #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // Just to make the behavior more identical. It is not a part of the problem. QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); #endif QApplication a(argc, argv); QMainWindow w; w.setMinimumWidth(300); w.setWindowTitle(QStringLiteral("Qt Version: ") + qVersion()); auto SomeMenu = new QMenu("Menu Action 2"); QMenu *fileMenu = w.menuBar()->addMenu("File"); w.setGeometry(-3000, 100, 300, 300); fileMenu->addAction("Action 1"); fileMenu->addMenu(SomeMenu); fileMenu->addAction("Action 3"); QObject::connect(SomeMenu, &QMenu::aboutToShow, SomeMenu, [=]() { SomeMenu->clear(); SomeMenu->addAction("SubItem 1"); SomeMenu->addAction("SubItem 2"); }); w.show(); return a.exec(); }