Creating a custom context menu in Qt

戏子无情 提交于 2019-12-24 03:39:20

问题


I'd like to create a special context menu for my application. The menu may have different shape and behaviour from the standard context menu.

For example I'd like to draw them circle-shaped or with ability to right-click on a menu entry, to open another menu about that menu item.

Of course, I'd like to integrate them as much as possible with the current framework, that is having action-based menu and such (but I'm not sure about what properties should have a menu to "fit" in the Qt framework).

So, my question is, where should I start to implement this? I see QMenu inherits from QWidget, so is it just sufficient to implement a custom QWidget for it? Should I instead inherit QMenu and extend it with custom graphics and event handling?

Thanks!


回答1:


I think you're asking a lot of QMenu to customize it so much. I'd recommend just making your own class that derives from QWidget and sets it's clipping bitmap (QWidget::setMask) and implement the paintEvent yourself. It'd probably be better to derive from QAbstractButton or QPushButton to get button press handling. QActions aren't going to buy you much here.



来源:https://stackoverflow.com/questions/14490748/creating-a-custom-context-menu-in-qt

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