2015-07-05 23 views

回答

2

您無法輕鬆設計此「擴展」按鈕,因爲該符號實際上是一個圖標。

然而,您可以訪問QToolButton小部件將圖標設置爲任何你喜歡的。在PyQt4中,你可以使用menubar.children()[0]。這應該與PyQt5一致。查看Qt5 source code,看起來擴展圖標總是首先創建,即使它未顯示,並且方法按創建順序返回對象(這是索引0)。

一旦您參照QToolButton,就可以使用menubar.children()[0].setIcon(my_qicon)(或類似)將圖標設置爲任何您喜歡的圖標。

0

因爲這是對谷歌前項修改「顯示更多」圖標之一:
另一種選擇是使用QToolbar。你可以做同樣的事情,除了第一個孩子是一個佈局,第二是QToolButton要:

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