Target

This application demostrates how to assign different menus for different widgets. The menus and toolbars of the widgets inside the tab widget (qmdiClient) will be merged into the main application window toolbars and menus.
There are 3 sets of widgets on this app:

  1. The start page - without menus nor toolbars (no menu to add it, don't close it)
  2. Text editor - text manipulating menus and toolbars
  3. Help browse - with browser related menus and toolbars
Please note, that it is OK to delete mdi clients from the main application, from the tab widget and also from the client themsevles using deleteLater().

You have also the option for recompile this application so that every mdi client will use a single toobar. Sometimes making several toolbars can look wierd to the user and it will be better from usability point of view to have a single toolbar. See the code for more details.

The code

The code in the clients does not have to worry about how and when the toolbars and menus will be merged. One just inherits the main window from qmdiHost, the clients from qmdiClient and the new widgets must be inserted into qmdiTab.
If a widget which does not inherit qmdiClient will be displayed on the tab widget, no menus and toolbars will be merged into the main window menus and toolbars.

This code is taken from the help browser. You only have to define actions, and connect them. Nothing more.

QexHelpBrowser::QexHelpBrowser( QUrl home, QWidget *parent )
	:QTextBrowser(parent)
{
	actionBack	= new QAction( QIcon(":images/prev.png"), tr("&Back"), this );
	actionNext	= new QAction( QIcon(":images/next.png"), tr("&Next"), this );
	actionHome	= new QAction( QIcon(":images/home.png"), tr("&Home"), this );
	actionCopy	= new QAction( QIcon(":images/copy.png"), tr("&Copy"), this  );
	actionZoomIn	= new QAction( QIcon(":images/zoomin.png"), tr("&Zoom in"), this  );
	actionZoomOut	= new QAction( QIcon(":images/zoomout.png"), tr("&Zoom out"), this  );

	connect( this, SIGNAL(backwardAvailable(bool)), actionBack, SLOT(setEnabled(bool)) );
	connect( this, SIGNAL(forwardAvailable(bool)), actionNext, SLOT(setEnabled(bool)) );
	connect( this, SIGNAL(copyAvailable(bool)), actionCopy, SLOT(setEnabled(bool)) );
	connect( actionBack, SIGNAL(triggered()), this, SLOT(backward()));
	connect( actionNext, SIGNAL(triggered()), this, SLOT(forward()));
	connect( actionHome, SIGNAL(triggered()), this, SLOT(goHome()));
	connect( actionZoomIn, SIGNAL(triggered()), this, SLOT(zoomIn()));
	connect( actionZoomOut, SIGNAL(triggered()), this, SLOT(zoomOut()));

	actionCopy->setEnabled(false);
	actionNext->setShortcut( QKeySequence("Alt+Right") );
	actionBack->setShortcut( QKeySequence("Alt+Left") );
	actionHome->setShortcut( QKeySequence("Alt+Home") );
	actionZoomIn->setShortcut( QKeySequence("Ctrl++") );
	actionZoomOut->setShortcut( QKeySequence("Ctrl+-") );

	// define the menus for this widget
	menus["&Edit"]		->addAction( actionCopy );
	
	menus["&Navigation"]->addAction( actionHome );
	menus["&Navigation"]->addAction( actionBack );
	menus["&Navigation"]->addAction( actionNext );
	menus["&Navigation"]->addSeparator();
	menus["&Navigation"]->addAction( actionZoomIn );
	menus["&Navigation"]->addAction( actionZoomOut );

	// define the toolbars for this widget
	toolbars["Edit operations"]->addAction( actionCopy );
	toolbars["Navigation"]->addAction( actionHome );
	toolbars["Navigation"]->addAction( actionBack );
	toolbars["Navigation"]->addAction( actionNext );
	toolbars["Navigation"]->addSeparator();
	toolbars["Navigation"]->addAction( actionZoomIn );
	toolbars["Navigation"]->addAction( actionZoomOut );
	
	homePage = home;
	setSource( homePage );
}