Danilo
Danilo

Reputation: 185

How to change right-arrow icon to access hidden menu items in QMenuBar using PyQt5?

enter image description here

I found no references about this in the documentation.

Upvotes: 0

Views: 832

Answers (2)

Onlyjus
Onlyjus

Reputation: 6149

Since this is one of the top items on google for modifying the "show more" icon:
Another option is to use a QToolbar. You can do the same thing except that the first child is a layout, second is the QToolButton that you want:

from qtpy import QtWidgets, QtGui
import sys

def call_back():
    print('pressed')

app = QtWidgets.QApplication([])

widget = QtWidgets.QWidget()
layout = QtWidgets.QGridLayout(widget)
toolbar = QtWidgets.QToolBar()
layout.addWIdget(toolbar)

# add some actions
for i in range(10):
    toolbar.addAction('test_{}'.format(i), call_back)

# change the icon, the first child is a layout!, the second it the toolbtn we want!
toolbar.children()[1].setIcon(QtGui.QIcon('path/to/image.png'))

widget.show()
app.exec_()
sys.exit()

enter image description here

Upvotes: 0

three_pineapples
three_pineapples

Reputation: 11849

You cannot easily style this "extension" button because that symbol is actually an icon.

You can however access the QToolButton widget to set the icon to whatever you like. In PyQt4 you get to it with menubar.children()[0]. This should be consistent with PyQt5. Looking at the Qt5 source code, it appears that the extension icon is always created first, even if it is not shown, and the children() method returns objects in the order in which they were created (this the index of 0).

Once you have a reference to the QToolButton, you can then set the icon to whatever you like with menubar.children()[0].setIcon(my_qicon) (or similar).

Upvotes: 2

Related Questions