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. QMenu setStyleSheet question

QMenu setStyleSheet question

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 739 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.
  • N Offline
    N Offline
    Noiro
    wrote on last edited by
    #1

    Hi everyone,
    Very new to QT and am currently making a menu and have a question about editing stylesheets.
    I'm wanting to remove or change the arrow on a sub menu and must be doing something stupid, as I can't get it to work. Some of the ways I've tried below

    submit_menu = QtGui.QMenu('Submit Options')
    submit_menu.setStyleSheet("QMenu::left-arrow { image: none;}")
    submit_menu.setStyleSheet("QMenu::right-arrow { image: none;}")
    submit_menu.setStyleSheet("QMenu::up-arrow {  image: none;}")
    submit_menu.setStyleSheet("QMenu::down-arrow {  image: none;}")
    

    or

    submit_menu = QtGui.QMenu('Submit Options')
    submit_menu.setStyleSheet("QMenu::left-arrow { image: url(/path/to/file.jpg);}")
    submit_menu.setStyleSheet("QMenu::right-arrow { image: url(/path/to/file.jpg);}")
    submit_menu.setStyleSheet("QMenu::up-arrow { image: url(/path/to/file.jpg);}")
    submit_menu.setStyleSheet("QMenu::down-arrow { image: url(/path/to/file.jpg);}")
    

    If anyone has any insights or better paths to try, would love to hear.

    JonBJ 1 Reply Last reply
    0
    • N Noiro

      Hi everyone,
      Very new to QT and am currently making a menu and have a question about editing stylesheets.
      I'm wanting to remove or change the arrow on a sub menu and must be doing something stupid, as I can't get it to work. Some of the ways I've tried below

      submit_menu = QtGui.QMenu('Submit Options')
      submit_menu.setStyleSheet("QMenu::left-arrow { image: none;}")
      submit_menu.setStyleSheet("QMenu::right-arrow { image: none;}")
      submit_menu.setStyleSheet("QMenu::up-arrow {  image: none;}")
      submit_menu.setStyleSheet("QMenu::down-arrow {  image: none;}")
      

      or

      submit_menu = QtGui.QMenu('Submit Options')
      submit_menu.setStyleSheet("QMenu::left-arrow { image: url(/path/to/file.jpg);}")
      submit_menu.setStyleSheet("QMenu::right-arrow { image: url(/path/to/file.jpg);}")
      submit_menu.setStyleSheet("QMenu::up-arrow { image: url(/path/to/file.jpg);}")
      submit_menu.setStyleSheet("QMenu::down-arrow { image: url(/path/to/file.jpg);}")
      

      If anyone has any insights or better paths to try, would love to hear.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @noiro
      My reading is that what you want cannot presently be done, or at least not this way.
      See https://forum.qt.io/topic/35113/how-to-hide-the-right-arrow-in-qmenu and https://bugreports.qt.io/browse/QTBUG-74501.
      At least check these out, as you are new to Qt and may be banging your head against a currently-sealed door?

      The only "insight" I would offer as that since the arrows etc. are part of how the native OS/windowing system chooses to display sub-menu-items, you really should not be trying to do what you are. Is this really important to you given that you are new to Qt and have plenty to learn?

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

        If anyone has any insights or better paths to try, would love to hear.

        What you did is the right way, except there's a quirk to that. You're setting the stylesheet on the wrong menu. If you want that stylesheet applied to submit_menu you need to set it on its parent. You can scope it with a name if you don't want it applied to all menus.

        1 Reply Last reply
        2
        • N Offline
          N Offline
          Noiro
          wrote on last edited by
          #4

          Thanks @JonB and @Chris-Kawa, it's a bit ugly but I've figured how to do it. For context what I was trying to achieve was a menu with sub menu's where you could click at any level and an action would occur. And the only way I could figure how to do it was to subclass qmenu and override the mouseReleaseEvent.
          But because of that, my lowest menu items had arrows. I had tried setting the lowest items to actions, but I think because I overrode the mouseReleaseEvent it meant the actions became disconnected.

          I'm certain there's a better way to do it, but it's been a chance to cut my teeth and stumble a bit into learning things.

          1 Reply Last reply
          0
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @noiro said in QMenu setStyleSheet question:

            I think because I overrode the mouseReleaseEvent it meant the actions became disconnected.

            well did you remember to call the base class of it so the base class can do what it normally does on that event ?

            1 Reply Last reply
            2

            • Login

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