[PyQt] QListWidget item editing
jnbarchan at gmail.com
Sat Dec 15 10:59:39 GMT 2018
On Fri, 14 Dec 2018 at 21:22, Maurizio Berti <maurizio.berti at gmail.com>
> [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:
> > 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
Thank you so much for replying. I get the gist now. I will try
implementing next week!
One thing I didn't like/expect: your Qt reply is that same as at the forum
(so I accept that's the way to do it now), you use the QStyledItemDelegate to
get the item being edited (from the QIndex parameter), I expected that to
be doable in the QListWidget class by (somehow) it knowing which item was
being edited instead, but it seems that's not the case.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the PyQt