QMenu* menu = new QMenu(parent); menu->setTitle("My Menu"); menu->setAttribute(Qt::WA_MenuBarVisible, false); menu->setAttribute(Qt::WA_QuitOnClose, false); menu->setAttribute(Qt::WA_DeleteOnClose, false); menu->setAttribute(Qt::WA_ShowWithoutActivating, true); menu->setCheckable(true);
QMenu* menu = new QMenu(parent); menu->setTitle("My Menu"); menu->setAttribute(Qt::WA_MenuBarVisible, false); menu->setAttribute(Qt::WA_DeleteOnClose, true);In this example, the setAttribute function is used to hide the menu bar and set the menu widget to be deleted on close. This means that when the user closes the menu, the widget will be deleted from memory. Package library: Qt Core Library.