Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QMenu and custom painting of the items

[SOLVED] QMenu and custom painting of the items

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 3.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by mrjj
    #1

    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 ?

    1 Reply Last reply
    0
    • Chris KawaC Online
      Chris KawaC Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      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.

      mrjjM 1 Reply Last reply
      0
      • Chris KawaC Chris Kawa

        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.

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @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. :)

        1 Reply Last reply
        0
        • Chris KawaC Online
          Chris KawaC Online
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @mrjj said:

          Seems to not care for the actual size of the returned widget. :)

          What size do you mean?
          The menu will honor both the sizeHint() of the widget and any minimum or maximum size it has set.

          If you mean something like resize() or setGeometry() then yes, they will be ignored, as is true for any widget in a layout.

          mrjjM 1 Reply Last reply
          0
          • Chris KawaC Chris Kawa

            @mrjj said:

            Seems to not care for the actual size of the returned widget. :)

            What size do you mean?
            The menu will honor both the sizeHint() of the widget and any minimum or maximum size it has set.

            If you mean something like resize() or setGeometry() then yes, they will be ignored, as is true for any widget in a layout.

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @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

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved