Mapping QWidget Using SignalMapper with PyQt
-
Hi all,
I have been really struggling with using SignalMapper with PyQt.
First, here's what I would like to do. I am using the model/view architecture with a table view. To keep it simple, let's say that I have two columns A and B. Column A consists of only QCheckBox's and column B has only QLineEdit's. When the checkbox in row i, column A is unchecked, I want to set the QLineEdit in row i, Column B as read only (i.e. gray it out). Therefore, I figure I need a reference to the QCheckbox that was toggled so that I can adjust the correct QLineEdit. This why I use signalMapper so that, immediately after the toggle, I can pass a reference to the toggled checkbox as a parameter to my custom slot.
Everything works fine when I do something like:
@
mapper = QSignalMapper()
checkBox = model.indexWidget(row,col)
checkBox.toggled.connect(mapper.map)
mapper.setMapping(checkBox, int)
mapper.mapped[int].connect(self.someCustomSlot)
@But if I try to pass a Qt object(such as QWidget) like:
@
mapper = QSignalMapper()
checkBox = model.indexWidget(row,col)
checkBox.toggled.connect(mapper.map)
mapper.setMapping(checkBox, checkBox)
mapper.mapped[QWidget].connect(self.someCustomSlot)
@It gives me the following error on Line 5: "KeyError: 'there is no matching overloaded signal'".
Due to the error message, I think that there may be an issue with the way that I am calling the signal named "mapped" on Line 5.
Is this a good case for a signal mapper? If not, then what would you recommend. If necessary, I can post my exact code tomorrow.
-
Update:
I found it easier just to pass a str to the signal named "mapped". The str consisted of the row and column of the toggled checkbox separated by a comma. Then, in my slot, i just used the str.split(',') to get the row and column.
Everything works as desired now.