Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QT How to remove the action menu item

when i add the widget to the main window, by default the action menu item will be present, how to remove that?

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()));

Thanks

like image 531
Naruto Avatar asked Oct 18 '25 14:10

Naruto


2 Answers

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

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

[Edit] If you want to hide QActions at runtime, you will find them as member of the QMainWindow's UI. For example if you have a QAction named actionTest, you will access it like that: this->ui->actionTest->setVisible(false);

like image 180
Patrice Bernassola Avatar answered Oct 21 '25 11:10

Patrice Bernassola


I know what you mean... you want to HIDE the DEFAULT CONTEXT MENU "Actions"....

You can do this in the Design section (not in code).

Then you see your Object-Stack on the right side like

  • MainWindow QMainWindow
    • centralWidget QWidget
      • webView QWebView

Now go to the property editor below...search for "contextMenuPolicy" and change it from "DefaultContextMenu" to "NoContextMenu" for every component if necessairy.

like image 36
Joel Avatar answered Oct 21 '25 09:10

Joel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!