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. What is the class of the children of a QMenu?
Forum Updated to NodeBB v4.3 + New Features

What is the class of the children of a QMenu?

Scheduled Pinned Locked Moved General and Desktop
13 Posts 3 Posters 6.6k Views 1 Watching
  • 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.
  • J Offline
    J Offline
    JulienMaille
    wrote on last edited by
    #4

    I'm still struggling with this. Let's formulate the problem differently:
    I want to change the stylesheet of all the widgets associated with a specific QAction.
    I can do this for actions added to a toolbar (in that case the corresponding widget is a QToolButton) but how do I access the widget that represent the action in a QMenu?

    QAction::associatedWidgets() does not help, it returns the QMenu not the menu item.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #5

      QMenu is one widget. Take a look at its code to see how it is rendered. It does not consist of QToolButtons or QActions. Note that QAction is not a widget at all. So, I guess what you are after is not possible, at least not without subclassing QMenu.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JulienMaille
        wrote on last edited by
        #6

        Thanks for your help Andre. I agree that QActions are not QWidgets. However there is something I don't understand:

        • when you add a QAction to a QToolBar, you "get" a QToolButton
        • when you add a QAction to a QMenu, do you "get" any widget?

        If QMenu is one widget, maybe it has child widgets?
        If it has no child, then I guess it is impossible to style its items?

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #7

          No, you do not get a widget for an action on a QMenu. However, you can style items using style sheets. Items support a whole array of pseudo states you can use. If you want to keep only a specified action enabled, you should also keep the container it is in enabled.

          1 Reply Last reply
          0
          • J Offline
            J Offline
            JulienMaille
            wrote on last edited by
            #8

            I tried to "style a specific item":http://doc.trolltech.com/latest/stylesheet-syntax.html#selector-types of a QMenu using selector, dynamic properties and object name.
            None of these methods worked.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #9

              You'll need to show more than just "It doesn't work" in order for us to be able to help you.

              1 Reply Last reply
              0
              • J Offline
                J Offline
                JulienMaille
                wrote on last edited by
                #10

                Ok, I set this stylesheet to my QMenu containing (among others) a QAction whose object name is "actionExit" and whose text is "Exit". I also added a dynamic property to the QAction: a boolean called "styleMe" set to true.
                @*#actionExit { background-color: blue; }
                *[text="Exit"] { background-color: blue; }
                *[styleMe="true"] { background-color: blue; }@
                I also tried with QWidget or QMenu::item instead of *

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #11

                  No, that won't work. Now you are trying to style the items in your menu as if they are widgets. Again, they are not. You can only use the QMenu::item subcontrol and the associated pseudo states.

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    JulienMaille
                    wrote on last edited by
                    #12

                    By pseudo states you mean this list?
                    @:checked
                    :disabled
                    :enabled
                    :focus
                    :hover
                    :indeterminate
                    :off
                    :on
                    :pressed
                    :unchecked @
                    Is this is the only way to set specific styling?

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      andre
                      wrote on last edited by
                      #13

                      Unless you want to reimplement QMenu itself, and do the rendering yourself: yes, it is.

                      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