问题
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