views:

725

answers:

2

Hi,

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

+1  A: 

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

Patrice Bernassola
Ok.. how to get the acces to qaction menu item?..i will be getting the actions list from the menu. if i iterate over it doesn't gives Action menu only.. so what to do?
Shadow
What do you want to exactly do?
Patrice Bernassola
i want to remove the Qaction menu from menubar.. so is there any way?for making set-visible we need to get access for it.. we are not getting only how to do?
Shadow
See Edit. But I'm not sure to understand the goal of your work. Are you trying to dynamically display QActions in the menuBar?
Patrice Bernassola
No.. i just want to hide the Action's name from menu item at runtime.."actiontest" represet wat in you edited section?."My goal is to hide the the default action name from menu item at runtime"
Shadow
actionTest is a QAction you have created using QtDesigner or you have manually added (in the constructor by example)
Patrice Bernassola
i am using the constructor to create menu..see in constructor how i am doing.. i have put up code in my quest above
Shadow
You have to keep a trace of your actions if you want to use it later as you want. Put verAction, displayAction and exitAction as member of your class so you have access to them at any time (don't forget that ownership stays to the menu bar and you must not delete them). An other way is to find a child of the menu bar regarding its name. Read this http://doc.trolltech.com/qq/qq03-big-brother.html#finding.children
Patrice Bernassola
A: 

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.

Joel