[SOLVED] QMenu and custom painting of the items
-
Hi
How would I go about painting the Menu items ?
I could not find any delegate for QMenu.I overrode
paintEvent ( QPaintEvent* e )But then I was in doubt if to paint all items or what
the paint event really want me to paint.
Like when to draw the item highlighted.So what is the correct / better way ?
-
The easiest way is to subclass QWidgetAction to return your custom item widget or don't subclass and just set a default widget if there's only one .
Since it's gonna be your own widget you'll get easy access to all the usual widget events like mouse enter/move/click, the state of it like enabled/disabled/focused etc., which you can use to decide how your widget looks like at any given time.
-
@Chris-Kawa
Ahh, I see
so my "menuitem" can be any widget I like.Is there any way besides
setStyleSheet ( "QMenu::item { height: 64px; margin: 0px; }" );
and making a QProxyStyle
For controlling The height of each "row"?Seems to not care for the actual size of the returned widget. :)
-
@mrjj said:
Seems to not care for the actual size of the returned widget. :)
What size do you mean?
The menu will honor both thesizeHint()
of the widget and any minimum or maximum size it has set.If you mean something like
resize()
orsetGeometry()
then yes, they will be ignored, as is true for any widget in a layout. -
@Chris-Kawa
Hi the size "my widget" when inserted.
If I make it say 64 it will just be cut and not be shown as 64 pix but seems to be clipped to a default Menu Item height.
But I see your point about layouts. Did not know the menu was/used one.
Will try with minimum and see what happens.Thank you