<div dir="ltr"><div>It seems there is an issue with the ownership of the QMenu created from the private QWidgetTextControl by calling createStandardContextMenu of QPlainTextEdit and QTextEdit (and the QWidgetLineControl for QLineEdit).</div><div>The Qt documentation says that the ownership is transferred to the caller, but this creates some problems in Python if a persistent reference isn't kept, which is a bit counterintuitive for common PyQt usage, as the menu parent is the text widget, which is normally enough to make it persistent even though no Python reference is kept.</div><div><br></div><div>This is normally not a problem if the menu is used with <span style="font-family:monospace">exec()</span>, but there are cases for which <span style="font-family:monospace">popup()</span> is preferred, or when it has to be used to "import" the existing menu actions for some other reason, because those actions get deleted as soon as the original menu is.<br></div><div><br></div><div>Even this simple example raises a RuntimeError exception, as the wrapped menu is immediately deleted:</div><div><br></div><div><span style="font-family:monospace">te = QTextEdit()</span></div><div><span style="font-family:monospace">for a in te.createStandardContextMenu().actions():</span></div><div><span style="font-family:monospace">    print(a.text())</span></div><div><br></div><div>Interestingly enough, there is a difference here:</div><div><br></div><div><span style="font-family:monospace">>>> te = QTextEdit()</span></div><div><span style="font-family:monospace">>>> te.createStandardContextMenu().actions()</span></div><div><span style="font-family:monospace">>>> print(len(te.findChildren(QMenu)))<br>0</span></div><div><span style="font-family:monospace">>>> te.createStandardContextMenu()</span><div><span style="font-family:monospace">>>> print(len(te.findChildren(QMenu)))</span></div><div><span style="font-family:monospace">1</span><br></div></div><div><br></div><div>Note that I purposely didn't keep any reference.<br></div><div><br></div><div>I temporarily worked around it by creating a further QMenu and reparenting all actions, but I suppose I could probably use sip as well.<br><br></div><div>This doesn't seem to happen with PySide, so I truly believe that this is a PyQt issue only.</div><div><br></div><div>Regards,</div><div>MaurizioB<br></div><br><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">È difficile avere una convinzione precisa quando si parla delle ragioni del cuore. - "Sostiene Pereira", Antonio Tabucchi<br><a href="http://www.jidesk.net" target="_blank">http://www.jidesk.net</a></div></div>