Python 工具栏V形不';添加QPushbuttons时不会展开

Python 工具栏V形不';添加QPushbuttons时不会展开,python,qt,pyside,toolbar,Python,Qt,Pyside,Toolbar,我正在尝试向工具栏添加一组可切换的按钮。当按钮的数量超过可显示的数量时,会显示V形图标,但它会变灰,不会显示剩余的内容 最初我有: toolbar = QtGui.QToolbar() newButton = QtGui.QPushButton('name') newButton.toggled.connect(myAction) toolbar.addWidget(newButton) 我了解到我需要创建一个customWidgetAction,因此我尝试了以下方法: toolbar = Q

我正在尝试向工具栏添加一组可切换的按钮。当按钮的数量超过可显示的数量时,会显示V形图标,但它会变灰,不会显示剩余的内容

最初我有:

toolbar = QtGui.QToolbar()
newButton = QtGui.QPushButton('name')
newButton.toggled.connect(myAction)
toolbar.addWidget(newButton)
我了解到我需要创建一个
customWidgetAction
,因此我尝试了以下方法:

toolbar = QtGui.QToolbar()
newButton = QtGui.QPushButton()
widgetAction = QtGui.QWidgetAction(newButton)
widgetAction.toggled.connect(myAction)
newWidget = widgetAction.createWidget(newButton)
toolbar.addWidget(newButton)

但是,使用此代码时,该按钮不会出现在工具栏中。有人指出我做错了什么吗?

我看到了同样的行为。如果将小部件添加到工具栏,而工具栏无法全部显示它们,则它将显示一个V形,但V形将变灰。但是,对于操作,V形不会变灰,它们将以下拉方式显示

我的示例仅使用标准
QAction
s:

from PySide import QtGui

app = QtGui.QApplication([])

tb = QtGui.QToolBar()

#tb.addWidget(QtGui.QPushButton('AAA'))
#tb.addWidget(QtGui.QPushButton('BBB'))
#tb.addWidget(QtGui.QPushButton('CCC')) # will not be shown in case the toolbar is too short, chevron will be greyed

tb.addAction(QtGui.QAction('AAA', tb))
tb.addAction(QtGui.QAction('BBB', tb))
tb.addAction(QtGui.QAction('CCC', tb))
tb.addAction(QtGui.QAction('DDD', tb))
tb.addAction(QtGui.QAction('EEE', tb))

tb.resize(50, 40)
tb.show()

app.exec_()
如果你想把动作和有用的东西联系起来,模式是:

toolbar = QtGui.QToolBar()
action = QtGui.QAction(icon, 'Create new scenario', toolbar)
action.triggered.connect(..)
toolbar.addAction(action)
QWidgetAction
似乎比
QAction
稍微复杂一些,尽管它也应该可以工作。如果不需要添加的功能,请使用
QAction
和简单图标