QT How to remove an action menu item

when I add a widget to the main window, by default an action menu item will be displayed, how to remove it?

menuBar()->setVisible(false);

verAction = new QAction(tr("&Version"),this);
menuBar()->addAction(verAction);
connect(verAction, SIGNAL(triggered()),this, SLOT(displayVersion()));

displayAction = new QAction(tr("&Display"),this);
menuBar()->addAction(displayAction);


 connect(displayAction, SIGNAL(triggered()),this, SLOT(displayMessage()));

exitAction = new QAction(tr("&Exit"),this);
menuBar()->addAction(exitAction);
connect(exitAction, SIGNAL(triggered()),this, SLOT(close()));

thank

+3
source share
3 answers

If you want to hide the QAction and display it when you need it, you can use the setVisible function .

If you want to remove the menu bar from QMainWindow, you can use the QT_NO_MENUBAR preprocessor to remove all uses of QMenuBar. If you are not using the tools provided by QMainWindow, perhaps you can use a simple QWidget as the main window in your application.

[] QActions , QMainWindow. , QAction actionTest, : this->ui->actionTest->setVisible(false);

+2

, ... ""....

"" ( ).

- ,

  • MainWindow QMainWindow
    • centralWidget QWidget
      • webView QWebView

... "contextMenuPolicy" "DefaultContextMenu" "NoContextMenu" , .

+2

"", :

// Remove context menu from the all widgets.
QWidgetList widgets = QApplication::allWidgets();
QWidget* w=0;
foreach(w,widgets) {
    w->setContextMenuPolicy(Qt::NoContextMenu);
}

, , , :)

(, QFriendFeed sample from forum.nokia.com)

+2

Source: https://habr.com/ru/post/1736065/


All Articles