1

I don't think this may be posssible but I had still want to try asking. In the attached screenshot, I have nested menus.

Is it possible to change the arrow keys icon as 'highlighted' by the red box?

I am trying to change the arrow key to a plus icon if there are no sub menu items found. The default arrow can be in use if there are sub menu items found.

enter image description here

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Teh Ki
  • 455
  • 1
  • 3
  • 14

1 Answers1

1

Yes, you can change the color of right-arrow.

But there is a trick to change it.

The truth of indicator is "branch-closed png file"

You can see the png file at the almost bottom on the page in the link.

So, it can not be solved by the pure-programmic way.

You prepare the picture in advance by yourself.

and please following code in QMenu constructor.

self.setStyleSheet("QMenu::right-arrow{image:url(stylesheet-branch-closed-red.png);}")

Attention:

stylesheet-branch-closed-red.png is my renamed picture.

You can download the original picture from the above link page.

you right-click the png picture and save as name.

This code comes from your past question.

class QCustomMenu(QtGui.QMenu):
    """Customized QMenu."""

    def __init__(self, title, parent=None):
        super(QCustomMenu, self).__init__(title=str(title), parent=parent)
        self.setup_menu()
        self.setStyleSheet("QMenu::right-arrow{image:url(stylesheet-branch-closed-red.png);}")
    def setup_menu(self):
        self.setContextMenuPolicy(QtCore.Qt.DefaultContextMenu)        
    def contextMenuEvent(self, event):
        no_right_click = [QAddAction]
        if any([isinstance(self.actionAt(event.pos()), instance) for instance in no_right_click]):
            return
        pos = event.pos()

    def addAction(self, action):
        super(QCustomMenu, self).addAction(action)

As the result, it will become like this.

You will dislike the white part of the arrow.

No problem, you can delete them clearly with a free-paint soft, but I didn't do it because it was needless.

branch-png

Haru
  • 1,884
  • 2
  • 12
  • 30
  • Many thanks for the detailed description. But can I kindly ask, if I would like the icon to be reset back to its default icon, is there a local path that I can get it from (Py)Qt? – Teh Ki Apr 11 '19 at 17:09
  • No,It is unnecessary to do it, if you use the default Icon, you simply delete the setStyleSheet argument.If so, you can automatically use the original one.If you can use a free-paint.soft and you set the appropriate path,you can change the icon to anything even though it is not a right-cursor(for example, the face of man or animal). – Haru Apr 12 '19 at 00:13