Sunday, July 6th 2008, 4:45pm UTC+1

You are not logged in.

  • Login
  • Register

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Friday, August 3rd 2007, 11:03pm

How to hide/remove a addMenu() menu

Hi,

I've added a menu and menu items using menuBar()->addMenu() and the subsequent addAction() calls. I know that calling clear() will remove the menu subitems added by addAction(), but how do I remove or hide the actual menu
item that was added by the addMenu() call.

I don't see any reference to this functionality.

Thanks!

Mark
  • Go to the top of the page

lifthrasir

Trainee

Posts: 159

Location: France

Occupation: Student

2

Friday, August 3rd 2007, 11:25pm

  • Go to the top of the page

Junior

Intermediate

Posts: 407

Location: San Antonio, TX USA

Occupation: Secure Engineer

3

Friday, August 3rd 2007, 11:42pm

RE: How to hide/remove a addMenu() menu

MrGarbage,

Below, if you double click on File 1 menu, it hides/shows File 2 menu.

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <QApplication>
#include <QWidget>
#include <QVBoxLayout>
#include <QMenuBar>
#include <QMenu>

int main( int argc, char **argv )
{
    QApplication app( argc, argv );

    QWidget *widget = new QWidget();
    QVBoxLayout *layout = new QVBoxLayout( widget );

    QMenuBar *menuBar = new QMenuBar();
    QMenu *menu = new QMenu( "File 1" );
    menu->menuAction()->setCheckable( true );
    QMenu *menu2 = new QMenu( "File 2" );
    menuBar->addMenu( menu );
    menuBar->addMenu( menu2 );

    QObject::connect( menu->menuAction(), SIGNAL( toggled( bool ) ),
            menu2->menuAction(), SLOT( setVisible( bool ) ) );

    layout->addWidget( menuBar );
    widget->show();

    return app.exec();
}


Hope this helps....

Junior
  • Go to the top of the page

Jess

Beginner

Posts: 5

Location: Puerto Vallarta, MX

4

Friday, February 15th 2008, 5:12pm

RE: How to hide/remove a addMenu() menu

Hi Mark,

Here is another solution:

If you're using Designer:

Source code

1
2
3
4
5
6
7
8
9
10
//copy the existing menu items
	QMenu *menuFile = ui.menuFile;
	QMenu *menuEdit = ui.menuEdit;
	QMenu *menuHelp = ui.menuHelp;

	ui.menubar->clear();

	//replace the menu items
	ui.menubar->addMenu(menuFile);
	ui.menubar->addMenu(menuHelp);


I found no method to hide the menus off the menu bar.

Jess
  • Go to the top of the page

5

Tuesday, May 13th 2008, 12:27pm

or also you can use somthing like this:

Source code

1
ui.menuHelp->menuAction()->setVisible(false);
  • Go to the top of the page

Rate this thread