Issue
I have a small app with a table. This table has some data and a button on each row. These buttons should allow the user to remove corresponding row data. I'm trying to implement it via the clicked
button signal, but I need to pass the row number, so I tried using QSignalMapper
, as shown in the excerpt below
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)"))
Problem is, my removeItem(self, index)
method is an instance method (because my table belongs to a specific class) and I'm having trouble mapping it in a way I can pass self
along with index
.
Currently, my code fails with the following error:
TypeError: removeItem() takes exactly 2 arguments (1 given)
Is there a way to make this work correctly? Or is it impossible to map instance methods with QSignalMapper
in PySide?
Solution
I tried to reproduce your code in PyQt but I'm not fully aware of the differences between Pyside and PyQt so my answer is more of a guess. Try to remove the second line of your code and replace the last one with:
self.mapper.mapped.connect(self.removeItem)
Answered By - finmor
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.