View Full Version : QToolBar: How do you suppress the right-click menu that allows hiding the toolbar?

10th June 2010, 07:27
How do you suppress the right-click menu that allows hiding a QToolBar ? The tool bars are part of a QMainWindow if that makes a difference.

Should be a very simple thing to do but my searches in the documentation have drawn a blank. I can see where the label text can be set and can set it to an empty string but the right-click option remains.

Chris W

10th June 2010, 07:35
You can override QWidget::contextMenuEvent and ignore the event.
That should I guess.

10th June 2010, 08:33
I fear it is too late by the time a context menu event has been sent. You did give me a hint that lead to:

// or
which I thought might work. The first but didn't seem to have any effect. The second stopped a context menu if clicked on the tool bar, but a context menu allowing hiding the tool bar would still come up if the right-click happened over the menu bar. I had to do:

on the QMainWindow to stop both. Seems that the context menus on the menu and tool bars of a main window are delegated upward.

10th June 2010, 09:26
Just Override QMenu * QMainWindow::createPopupMenu ()

QMenu * MyMainWindow::createPopupMenu ()
return NULL;

6th November 2012, 15:02
Found a nice answer on StackOverflow. Just call:


inside your QMainWindow subclass.


6th November 2012, 21:42
That information was already in this thread two years ago ;)