How to disable the context menu of a QDockWidget title bar

跟風遠走 提交于 2019-12-10 07:53:22

问题


I have a couple of QDockWidgets that are all not closabale (using Qt 5.6). Therefore, the context menu that is displayed when right-clicking a title bar of one of them only has disabled entries, and I would like to disable the whole context menu.

I tried to set the contextMenuPolicy to NoContextMenu without success.

I then tried to use a subclass of QDockWidget, override the ContextMenuEvent and ignore it. The menu is still displayed.

I then tried to install an event filter to catch the ContextMenuEvent, but it did not catch any, just PaintEvents, ResizeEvents etc.

I'm out of ideas … any help would be greatly appreciated!


回答1:


As per the comments it is necessary to set the context menu policy on the QDockWidget to Qt::PreventContextMenu...

dock_widget->setContextMenuPolicy(Qt::PreventContextMenu);

rather than simply Qt::NoContextMenu. From the documentation Qt::NoContextMenu simply defers the context menu handling to the parent widget rather than preventing it entirely.



来源:https://stackoverflow.com/questions/44601362/how-to-disable-the-context-menu-of-a-qdockwidget-title-bar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!