【发布时间】:2015-02-24 11:41:12
【问题描述】:
-
我希望 QToolBar 像这样被实例化:
tools = customTools(actions=['action_one', 'action_two', 'action_three']) -
以及要编程添加的classmethods,所以有(对应每个动作发出的信号):
tools.action_one() tools.action_two()... -
这些方法应在“工具”之外可用,以便它们可以调用其他类的方法,例如:
class customTools(QtGui.QToolBar): """represents a custom QToolBar""" ... def action_one(self): some_other_classes.function() -
现在,我卡在这里:
class customTools(QtGui.QToolBar): def __init__(self, actions=[]): QtGui.QToolBar.__init__(self, parent=None) #actions to toolbar QAction for name in actions: action = QtGui.QAction(name, self) self.addAction(action) action.triggered[()].connect( lambda name=name: self.tool_name(name)) def tool_name(self, name): # stuck here...
【问题讨论】:
标签: python-2.7 lambda closures pyqt4