我有一个带有表格的小应用程序。该表在每一行上都有一些数据和一个按钮。这些按钮应允许用户删除相应的行数据。我试图通过clicked
按钮信号来实现它,但我需要传递的行数,所以我尝试使用QSignalMapper
,如图中摘录如下使用QSignalMapper和实例方法将PySide连接到信号
btnRemoveItem = QPushButton()
btnRemoveItem.clicked.connect(self.removeItem)
self.mapper = QSignalMapper(self)
self.connect(btnRemoveItem, QtCore.SIGNAL("clicked()"), self.mapper,
QtCore.SLOT("map()"))
self.mapper.setMapping(btnRemoveItem, nextRow)
self.connect(self.mapper, QtCore.SIGNAL("mapped(int)"), self.removeItem(),
QtCore.SIGNAL("clicked(int)"))
问题是,我removeItem(self, index)
方法是一个实例方法(因为我的表属于一个特定的类),我无法通过self
以及index
的方式映射它。
目前,我的代码失败,出现以下错误:
TypeError: removeItem() takes exactly 2 arguments (1 given)
有没有办法正确地做这项工作?或者是否不可能将实例方法与PySide中的QSignalMapper
映射?
非常感谢!它非常有效! – Mauren