Unsolved QMenu setStyleSheet question
-
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 belowsubmit_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.
-
@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?
-
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. -
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.
-
@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 ?