[PyQt] QListWidget item editing
maurizio.berti at gmail.com
Fri Dec 14 21:21:39 GMT 2018
[sending again as I forgot to reply to the list]
> is that about right (it does seem to work)?
The "name" argument of signals is not required as long as you use the same
name for the attribute.
> Right? And then how do I emit that signal? Is it like:
> Is that use of a lambda right (that's a Python/PyQt question)?
> And how do I get at from within the QListWidget which QListWidgetItem to
pass as someItemWidget (that's probably a Qt question)?
Not exactly. If you need to pass an argument to a function within a lambda,
it has to be in the lambda arguments too, otherwise python will try to look
for the argument name in the local scope and eventually raise an error if
it doesn't exist.
Seeing your implementation I'd modify the original editStarted signal of
the delegate and add a QModelIndex argument:
editStarted = QtCore.pyqtSignal(QtCore.QModelIndex)
then emit the signal from the setEditorData method with its index argument:
At this point you can connect it with this lambda in the QListWidget init:
styledItemDelegate.editStarted.connect(lambda index: self.editStarted.emit
In this way the the lambda will receive the index argument previously
emitted, convert it to a list widget item and finally emit its own
editStarted signal with the correct list widget item argument.
È difficile avere una convinzione precisa quando si parla delle ragioni del
cuore. - "Sostiene Pereira", Antonio Tabucchi
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the PyQt