<div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-family:tahoma,sans-serif">I have started a thread on the Qt Forum at <a href="https://forum.qt.io/topic/97628/qlistwidget-item-editing">https://forum.qt.io/topic/97628/qlistwidget-item-editing</a>. The people there are very helpful about how to do things for Qt in C++, but often there isn't really anyone to help out correctly for PyQt/Python. I need to extend what I have done in PyQt, and I think I might need some PyQt help to sort it out. Someone here like the excellent & kind <a class="gmail_plusreply" id="gmail-plusReplyChip-0" href="mailto:me@the-compiler.org" tabindex="-1">@Florian Bruhin</a> will probably be able to sort me out immediately! :)<br></div><div class="gmail_default" style="font-family:tahoma,sans-serif"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif">I won't repeat the whole stuff. Basically, I was given to translate:</div><div class="gmail_default" style="font-family:tahoma,sans-serif;margin-left:40px"><pre class="gmail-markdown-highlight"><code class="gmail-language-cpp gmail-hljs"><span class="gmail-hljs-keyword"><span class="gmail-hljs-keyword"><span class="gmail-hljs-keyword"><span class="gmail-hljs-keyword"><span class="gmail-hljs-keyword"><span class="gmail-hljs-keyword">class</span></span></span></span></span></span> SignalItemDelegate : <span class="gmail-hljs-keyword"><span class="gmail-hljs-keyword"><span class="gmail-hljs-keyword"><span class="gmail-hljs-keyword"><span class="gmail-hljs-keyword"><span class="gmail-hljs-keyword">public</span></span></span></span></span></span> QStyledItemDelegate{
<span class="gmail-hljs-function"><span class="gmail-hljs-function"><span class="gmail-hljs-function"><span class="gmail-hljs-function"><span class="gmail-hljs-function"><span class="gmail-hljs-function">Q_OBJECT
</span></span></span></span></span><span class="gmail-hljs-title"><span class="gmail-hljs-function"><span class="gmail-hljs-title"><span class="gmail-hljs-function"><span class="gmail-hljs-title"><span class="gmail-hljs-function"><span class="gmail-hljs-title"><span class="gmail-hljs-function"><span class="gmail-hljs-title"><span class="gmail-hljs-function"><span class="gmail-hljs-title">Q_DISABLE_COPY</span></span></span></span></span></span></span></span></span></span></span><span class="gmail-hljs-params"><span class="gmail-hljs-function"><span class="gmail-hljs-params"><span class="gmail-hljs-function"><span class="gmail-hljs-params"><span class="gmail-hljs-function"><span class="gmail-hljs-params"><span class="gmail-hljs-function"><span class="gmail-hljs-params"><span class="gmail-hljs-function"><span class="gmail-hljs-params">(SignalItemDelegate)</span></span></span></span></span></span></span></span></span></span></span><span class="gmail-hljs-function"><span class="gmail-hljs-function"><span class="gmail-hljs-function"><span class="gmail-hljs-function"><span class="gmail-hljs-function">
</span></span></span></span></span><span class="gmail-hljs-keyword"><span class="gmail-hljs-function"><span class="gmail-hljs-keyword"><span class="gmail-hljs-function"><span class="gmail-hljs-keyword"><span class="gmail-hljs-function"><span class="gmail-hljs-keyword"><span class="gmail-hljs-function"><span class="gmail-hljs-keyword"><span class="gmail-hljs-function"><span class="gmail-hljs-keyword">public</span></span></span></span></span></span></span></span></span></span></span><span class="gmail-hljs-function"><span class="gmail-hljs-function"><span class="gmail-hljs-function"><span class="gmail-hljs-function"><span class="gmail-hljs-function">:
</span></span></span></span></span><span class="gmail-hljs-keyword"><span class="gmail-hljs-function"><span class="gmail-hljs-keyword"><span class="gmail-hljs-function"><span class="gmail-hljs-keyword"><span class="gmail-hljs-function"><span class="gmail-hljs-keyword"><span class="gmail-hljs-function"><span class="gmail-hljs-keyword"><span class="gmail-hljs-function"><span class="gmail-hljs-keyword">explicit</span></span></span></span></span></span></span></span></span></span></span><span class="gmail-hljs-function"><span class="gmail-hljs-function"><span class="gmail-hljs-function"><span class="gmail-hljs-function"><span class="gmail-hljs-function"> </span></span></span></span></span><span class="gmail-hljs-title"><span class="gmail-hljs-function"><span class="gmail-hljs-title"><span class="gmail-hljs-function"><span class="gmail-hljs-title"><span class="gmail-hljs-function"><span class="gmail-hljs-title"><span class="gmail-hljs-function"><span class="gmail-hljs-title"><span class="gmail-hljs-function"><span class="gmail-hljs-title">SignalItemDelegate</span></span></span></span></span></span></span></span></span></span></span><span class="gmail-hljs-params"><span class="gmail-hljs-function"><span class="gmail-hljs-params"><span class="gmail-hljs-function"><span class="gmail-hljs-params"><span class="gmail-hljs-function"><span class="gmail-hljs-params"><span class="gmail-hljs-function"><span class="gmail-hljs-params"><span class="gmail-hljs-function"><span class="gmail-hljs-params">(QObject* parent = Q_NULLPTR)</span></span></span></span></span></span></span></span></span></span></span><span class="gmail-hljs-function"><span class="gmail-hljs-function"><span class="gmail-hljs-function"><span class="gmail-hljs-function"><span class="gmail-hljs-function">:</span></span></span></span></span><span class="gmail-hljs-title"><span class="gmail-hljs-function"><span class="gmail-hljs-title"><span class="gmail-hljs-function"><span class="gmail-hljs-title"><span class="gmail-hljs-function"><span class="gmail-hljs-title"><span class="gmail-hljs-function"><span class="gmail-hljs-title"><span class="gmail-hljs-function"><span class="gmail-hljs-title">QStyledItemDelegate</span></span></span></span></span></span></span></span></span></span></span><span class="gmail-hljs-params"><span class="gmail-hljs-function"><span class="gmail-hljs-params"><span class="gmail-hljs-function"><span class="gmail-hljs-params"><span class="gmail-hljs-function"><span class="gmail-hljs-params"><span class="gmail-hljs-function"><span class="gmail-hljs-params"><span class="gmail-hljs-function"><span class="gmail-hljs-params">(parent)</span></span></span></span></span></span></span></span></span></span></span></span>{
QObject::connect(<span class="gmail-hljs-keyword"><span class="gmail-hljs-keyword"><span class="gmail-hljs-keyword"><span class="gmail-hljs-keyword"><span class="gmail-hljs-keyword"><span class="gmail-hljs-keyword">this</span></span></span></span></span></span>,&SignalItemDelegate::closeEditor,<span class="gmail-hljs-keyword"><span class="gmail-hljs-keyword"><span class="gmail-hljs-keyword"><span class="gmail-hljs-keyword"><span class="gmail-hljs-keyword"><span class="gmail-hljs-keyword">this</span></span></span></span></span></span>,&SignalItemDelegate::editFinished);
}
<span class="gmail-hljs-function"><span class="gmail-hljs-keyword"><span class="gmail-hljs-function"><span class="gmail-hljs-keyword"><span class="gmail-hljs-function"><span class="gmail-hljs-keyword"><span class="gmail-hljs-function"><span class="gmail-hljs-keyword"><span class="gmail-hljs-function"><span class="gmail-hljs-keyword"><span class="gmail-hljs-function"><span class="gmail-hljs-keyword">void</span></span></span></span></span></span></span></span></span></span></span><span class="gmail-hljs-function"><span class="gmail-hljs-function"><span class="gmail-hljs-function"><span class="gmail-hljs-function"><span class="gmail-hljs-function"> </span></span></span></span></span><span class="gmail-hljs-title"><span class="gmail-hljs-function"><span class="gmail-hljs-title"><span class="gmail-hljs-function"><span class="gmail-hljs-title"><span class="gmail-hljs-function"><span class="gmail-hljs-title"><span class="gmail-hljs-function"><span class="gmail-hljs-title"><span class="gmail-hljs-function"><span class="gmail-hljs-title">setEditorData</span></span></span></span></span></span></span></span></span></span></span><span class="gmail-hljs-params"><span class="gmail-hljs-function"><span class="gmail-hljs-params"><span class="gmail-hljs-function"><span class="gmail-hljs-params"><span class="gmail-hljs-function"><span class="gmail-hljs-params"><span class="gmail-hljs-function"><span class="gmail-hljs-params"><span class="gmail-hljs-function"><span class="gmail-hljs-params">(QWidget *editor, </span></span></span></span></span></span></span></span></span></span><span class="gmail-hljs-keyword"><span class="gmail-hljs-function"><span class="gmail-hljs-params"><span class="gmail-hljs-keyword"><span class="gmail-hljs-function"><span class="gmail-hljs-params"><span class="gmail-hljs-keyword"><span class="gmail-hljs-function"><span class="gmail-hljs-params"><span class="gmail-hljs-keyword"><span class="gmail-hljs-function"><span class="gmail-hljs-params"><span class="gmail-hljs-keyword"><span class="gmail-hljs-function"><span class="gmail-hljs-params"><span class="gmail-hljs-keyword">const</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="gmail-hljs-function"><span class="gmail-hljs-params"><span class="gmail-hljs-function"><span class="gmail-hljs-params"><span class="gmail-hljs-function"><span class="gmail-hljs-params"><span class="gmail-hljs-function"><span class="gmail-hljs-params"><span class="gmail-hljs-function"><span class="gmail-hljs-params"> QModelIndex &index)</span></span></span></span></span></span></span></span></span></span></span><span class="gmail-hljs-function"><span class="gmail-hljs-function"><span class="gmail-hljs-function"><span class="gmail-hljs-function"><span class="gmail-hljs-function"> </span></span></span></span></span><span class="gmail-hljs-keyword"><span class="gmail-hljs-function"><span class="gmail-hljs-keyword"><span class="gmail-hljs-function"><span class="gmail-hljs-keyword"><span class="gmail-hljs-function"><span class="gmail-hljs-keyword"><span class="gmail-hljs-function"><span class="gmail-hljs-keyword"><span class="gmail-hljs-function"><span class="gmail-hljs-keyword">const</span></span></span></span></span></span></span></span></span></span></span><span class="gmail-hljs-function"><span class="gmail-hljs-function"><span class="gmail-hljs-function"><span class="gmail-hljs-function"><span class="gmail-hljs-function"> Q_DECL_OVERRIDE</span></span></span></span></span></span>{
editStarted();
<span class="gmail-hljs-keyword"><span class="gmail-hljs-keyword"><span class="gmail-hljs-keyword"><span class="gmail-hljs-keyword"><span class="gmail-hljs-keyword"><span class="gmail-hljs-keyword">return</span></span></span></span></span></span> QStyledItemDelegate::setEditorData(editor,index);
}
Q_SIGNALS:
<span class="gmail-hljs-function"><span class="gmail-hljs-keyword"><span class="gmail-hljs-function"><span class="gmail-hljs-keyword"><span class="gmail-hljs-function"><span class="gmail-hljs-keyword"><span class="gmail-hljs-function"><span class="gmail-hljs-keyword"><span class="gmail-hljs-function"><span class="gmail-hljs-keyword"><span class="gmail-hljs-function"><span class="gmail-hljs-keyword">void</span></span></span></span></span></span></span></span></span></span></span><span class="gmail-hljs-function"><span class="gmail-hljs-function"><span class="gmail-hljs-function"><span class="gmail-hljs-function"><span class="gmail-hljs-function"> </span></span></span></span></span><span class="gmail-hljs-title"><span class="gmail-hljs-function"><span class="gmail-hljs-title"><span class="gmail-hljs-function"><span class="gmail-hljs-title"><span class="gmail-hljs-function"><span class="gmail-hljs-title"><span class="gmail-hljs-function"><span class="gmail-hljs-title"><span class="gmail-hljs-function"><span class="gmail-hljs-title">editStarted</span></span></span></span></span></span></span></span></span></span></span><span class="gmail-hljs-params"><span class="gmail-hljs-function"><span class="gmail-hljs-params"><span class="gmail-hljs-function"><span class="gmail-hljs-params"><span class="gmail-hljs-function"><span class="gmail-hljs-params"><span class="gmail-hljs-function"><span class="gmail-hljs-params"><span class="gmail-hljs-function"><span class="gmail-hljs-params">()</span></span></span></span></span></span></span></span></span></span></span></span>;
<span class="gmail-hljs-function"><span class="gmail-hljs-keyword"><span class="gmail-hljs-function"><span class="gmail-hljs-keyword"><span class="gmail-hljs-function"><span class="gmail-hljs-keyword"><span class="gmail-hljs-function"><span class="gmail-hljs-keyword"><span class="gmail-hljs-function"><span class="gmail-hljs-keyword"><span class="gmail-hljs-function"><span class="gmail-hljs-keyword">void</span></span></span></span></span></span></span></span></span></span></span><span class="gmail-hljs-function"><span class="gmail-hljs-function"><span class="gmail-hljs-function"><span class="gmail-hljs-function"><span class="gmail-hljs-function"> </span></span></span></span></span><span class="gmail-hljs-title"><span class="gmail-hljs-function"><span class="gmail-hljs-title"><span class="gmail-hljs-function"><span class="gmail-hljs-title"><span class="gmail-hljs-function"><span class="gmail-hljs-title"><span class="gmail-hljs-function"><span class="gmail-hljs-title"><span class="gmail-hljs-function"><span class="gmail-hljs-title">editFinished</span></span></span></span></span></span></span></span></span></span></span><span class="gmail-hljs-params"><span class="gmail-hljs-function"><span class="gmail-hljs-params"><span class="gmail-hljs-function"><span class="gmail-hljs-params"><span class="gmail-hljs-function"><span class="gmail-hljs-params"><span class="gmail-hljs-function"><span class="gmail-hljs-params"><span class="gmail-hljs-function"><span class="gmail-hljs-params">()</span></span></span></span></span></span></span></span></span></span></span></span>;
};</code></pre></div><div class="gmail_default" style="font-family:tahoma,sans-serif">for which I came up with:</div><div class="gmail_default" style="font-family:tahoma,sans-serif;margin-left:40px"><pre style="background-color:rgb(255,255,255);color:rgb(0,0,0);font-family:"DejaVu Sans Mono";font-size:9pt"><span style="color:rgb(0,0,128);font-weight:bold">class </span>JEditableListStyledItemDelegate(QtWidgets.QStyledItemDelegate):<br> <span style="color:rgb(128,128,128);font-style:italic"># class variable for "editStarted" signal<br></span><span style="color:rgb(128,128,128);font-style:italic"> </span>editStarted = QtCore.pyqtSignal(<span style="color:rgb(102,0,153)">name</span>=<span style="color:rgb(0,128,128);font-weight:bold">'editStarted'</span>)<br> <span style="color:rgb(128,128,128);font-style:italic"># class variable for "editFinished" signal<br></span><span style="color:rgb(128,128,128);font-style:italic"> </span>editFinished = QtCore.pyqtSignal(<span style="color:rgb(102,0,153)">name</span>=<span style="color:rgb(0,128,128);font-weight:bold">'editFinished'</span>)<br><br> <span style="color:rgb(0,0,128);font-weight:bold">def </span><span style="color:rgb(178,0,178)">__init__</span>(<span style="color:rgb(148,85,141)">self</span>, parent: QtCore.QObject=<span style="color:rgb(0,0,128);font-weight:bold">None</span>):<br> <span style="color:rgb(0,0,128)">super</span>().<span style="color:rgb(178,0,178)">__init__</span>(parent)<br><br> <span style="color:rgb(148,85,141)">self</span>.closeEditor.connect(<span style="color:rgb(148,85,141)">self</span>.editFinished)<br><br> <span style="color:rgb(0,0,128);font-weight:bold">def </span>setEditorData(<span style="color:rgb(148,85,141)">self</span>, editor: QtWidgets.QWidget, index: QtCore.QModelIndex):<br> <span style="color:rgb(148,85,141)">self</span>.editStarted.emit()<br> <span style="color:rgb(0,0,128);font-weight:bold">return </span><span style="color:rgb(0,0,128)">super</span>().setEditorData(editor, index)<br><br><br><span style="color:rgb(0,0,128);font-weight:bold">class </span>JEditableListWidget(QtWidgets.QListWidget):<br> <span style="color:rgb(128,128,128);font-style:italic"># class variable for "editStarted" signal<br></span><span style="color:rgb(128,128,128);font-style:italic"> </span>editStarted = QtCore.pyqtSignal(<span style="color:rgb(102,0,153)">name</span>=<span style="color:rgb(0,128,128);font-weight:bold">'editStarted'</span>)<br> <span style="color:rgb(128,128,128);font-style:italic"># class variable for "editFinished" signal<br></span><span style="color:rgb(128,128,128);font-style:italic"> </span>editFinished = QtCore.pyqtSignal(<span style="color:rgb(102,0,153)">name</span>=<span style="color:rgb(0,128,128);font-weight:bold">'editFinished'</span>)<br><br> <span style="color:rgb(0,0,128);font-weight:bold">def </span><span style="color:rgb(178,0,178)">__init__</span>(<span style="color:rgb(148,85,141)">self</span>, parent: QtWidgets.QWidget=<span style="color:rgb(0,0,128);font-weight:bold">None</span>):<br> <span style="color:rgb(0,0,128)">super</span>().<span style="color:rgb(178,0,178)">__init__</span>(parent)<br><br> styledItemDelegate = JEditableListStyledItemDelegate(<span style="color:rgb(148,85,141)">self</span>)<br> styledItemDelegate.editStarted.connect(<span style="color:rgb(148,85,141)">self</span>.editStarted)<br> styledItemDelegate.editFinished.connect(<span style="color:rgb(148,85,141)">self</span>.editFinished)<br> <span style="color:rgb(148,85,141)">self</span>.setItemDelegate(styledItemDelegate)<br></pre></div><div class="gmail_default" style="font-family:tahoma,sans-serif"><i><br></i></div><div class="gmail_default" style="font-family:tahoma,sans-serif"><u><i>My first question is</i></u>: is that about right (it does seem to work)?<br></div><div class="gmail_default" style="font-family:tahoma,sans-serif"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif"><u><i>My second question is</i></u>: if you read my latest <a href="https://forum.qt.io/topic/97628/qlistwidget-item-editing/10">https://forum.qt.io/topic/97628/qlistwidget-item-editing/10</a>, you'll see I need to introduce a parameter to my signals from my <span style="font-family:monospace,monospace">QListWidget</span> to the outside world for which <span style="font-family:monospace,monospace">QListWidgetItem</span> is being edited. I believe I need to change my <span style="font-family:monospace,monospace">QListWidget</span> signals like:</div><div class="gmail_default" style="font-family:tahoma,sans-serif;margin-left:40px"><pre style="background-color:rgb(255,255,255);color:rgb(0,0,0);font-family:"DejaVu Sans Mono";font-size:9pt"><span style="color:rgb(0,0,128);font-weight:bold">class </span>JEditableListWidget(QtWidgets.QListWidget):<br> <span style="color:rgb(128,128,128);font-style:italic"># class variable for "editStarted" signal, including item<br></span><span style="color:rgb(128,128,128);font-style:italic"> </span>editStarted = QtCore.pyqtSignal(QtWidgets.QListWidgetItem, <span style="color:rgb(102,0,153)">name</span>=<span style="color:rgb(0,128,128);font-weight:bold">'editStarted'</span>)</pre></div><div class="gmail_default" style="font-family:tahoma,sans-serif">Right? And then how do I emit that signal? Is it like:</div><div class="gmail_default" style="font-family:tahoma,sans-serif;margin-left:40px"><pre class="gmail-markdown-highlight"><code class="gmail-hljs gmail-css"><span class="gmail-hljs-selector-tag">styledItemDelegate</span><span class="gmail-hljs-selector-class">.editStarted</span><span class="gmail-hljs-selector-class">.connect</span>(<span class="gmail-hljs-selector-tag">lambda</span>: <span class="gmail-hljs-selector-tag">self</span><span class="gmail-hljs-selector-class">.editStarted</span><span class="gmail-hljs-selector-class">.emit</span>(<span class="gmail-hljs-selector-tag">someItemWidget</span>))</code></pre></div><div class="gmail_default" style="font-family:tahoma,sans-serif">?</div><div class="gmail_default" style="font-family:tahoma,sans-serif"><ul><li>Is that use of a <span style="font-family:monospace,monospace">lambda</span> right (that's a Python/PyQt question)?</li><li>And how do I get at from within the <span style="font-family:monospace,monospace">QListWidget</span> which <span style="font-family:monospace,monospace">QListWidgetItem</span> to pass as <span style="font-family:monospace,monospace">someItemWidget</span> (that's probably a Qt question)?</li></ul></div><div class="gmail_default" style="font-family:tahoma,sans-serif"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif">Many thanks to anyone who responds!</div><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><span style="font-family:tahoma,sans-serif">Kindest,</span></div><div><span style="font-family:tahoma,sans-serif">Jonathan</span></div></div></div></div></div></div></div></div>