Is there a way to prevent the hide operation of a toolbar?

Sergey Skoblikov picture Sergey Skoblikov · Mar 16, 2009 · Viewed 7.5k times · Source

In Qt, if I right-click on a toolbar the menu will be shown that allows me to hide the toolbar. I need to disable this functionality because I don't want the toolbar to possible to hide. Is there a way to do this?

Answer

Nolan Amy picture Nolan Amy · Jan 26, 2012

I was able to set the ContextMenuPolicy directly on the toolbar (not the main window), as long as I used either Qt::PreventContextMenu or Qt::ActionsContextMenu. Prevent eliminated the context menu and made right-click have no effect on the toolbar, while Actions made a nice context menu composed of the actions already in my toolbar. Qt::NoContextMenu didn't seem to have any effect.

toolbar->setContextMenuPolicy(Qt::PreventContextMenu);