[PyQt] QListWidget item editing

Maurizio Berti 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)?

Seems right.
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:
> styledItemDelegate.editStarted.connect(lambda:
self.editStarted.emit(someItemWidget))
> 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:

self.editStarted.emit(index)

At this point you can connect it with this lambda in the QListWidget init:

styledItemDelegate.editStarted.connect(lambda index: self.editStarted.emit
(self.itemFromIndex(index))

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.

Regards,
Maurizio

-- 
È difficile avere una convinzione precisa quando si parla delle ragioni del
cuore. - "Sostiene Pereira", Antonio Tabucchi
http://www.jidesk.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20181214/72cee7db/attachment-0001.html>


More information about the PyQt mailing list