AkiRoss
AkiRoss

Reputation: 12273

Creating a custom context menu in Qt

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!

Upvotes: 2

Views: 1444

Answers (1)

cppguy
cppguy

Reputation: 3713

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.

Upvotes: 3

Related Questions