<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">You can't. You need to create a custom QStyledItemDelegate and use QStyledItemDelegate.createEditor instead.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jul 25, 2024 at 8:29 PM Tassos Tzavellas <<a href="mailto:tassos.tzavellas@ansys.com">tassos.tzavellas@ansys.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="msg-3264423711009482241">




<div dir="ltr">
<div style="text-align:left;text-indent:0px;margin:0px;font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:11pt;color:rgb(0,0,0)">
Hi,<br>
<br>
I want to use the QItemEditorFactory to register a CustomEditor class for my own CustomType. The official Qt
<a href="https://doc.qt.io/qtforpython-6/overviews/custom-types.html" id="m_-3264423711009482241OWAc2b431f4-370c-b43b-a96a-8f1f001d4c38" title="https://doc.qt.io/qtforpython-6/overviews/custom-types.html" style="margin:0px" target="_blank">
documentation</a> dictates the use of either of these two macros for registering custom types to the Qt Meta type system (and subsequent use in the factory): </div>
<div style="text-align:left;text-indent:0px;margin:0px;font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:11pt;color:rgb(0,0,0)">
Q_DECLARE_METATYPE and qRegisterMetaType. </div>
<div style="text-align:left;text-indent:0px;margin:0px;font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:11pt;color:rgb(0,0,0)">
<br>
</div>
<div style="text-align:left;text-indent:0px;margin:0px;font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:11pt;color:rgb(0,0,0)">
Since I don't care about signals/slots mechanism, the first macro is the obvious choice.</div>
<div style="text-align:left;text-indent:0px;margin:0px;font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:11pt;color:rgb(0,0,0)">
<br>
</div>
<div style="text-align:left;text-indent:0px;margin:0px;font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:11pt;color:rgb(0,0,0)">
>From the study of the <a href="https://www.riverbankcomputing.com/static/Docs/PyQt5/api/qtcore/qmetatype.html" id="m_-3264423711009482241LPlnk761904" title="https://www.riverbankcomputing.com/static/Docs/PyQt5/api/qtcore/qmetatype.html" target="_blank">
PyQt documentation</a>, this macro should be supported and probably it should exist by importing the PyQt5.QtCore.QMetaType module.</div>
<div style="text-align:left;text-indent:0px;margin:0px;font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:11pt;color:rgb(0,0,0)">
<br>
However, that is not the case. My python interpreter (version 3.9.7) gives me an error : NameError: name 'Q_DECLARE_METATYPE' is not defined. <br>
<br>
Here is a snippet from my source code:<br>
<br>
from PyQt5.QtCore import QMetaType</div>
<div style="text-align:left;text-indent:0px;margin:0px;font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:11pt;color:rgb(0,0,0)">
class CustomType:</div>
<div style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:11pt;color:rgb(0,0,0)">
    def __init__(self) -> None:</div>
<div style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:11pt;color:rgb(0,0,0)">
        pass</div>
<div style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:11pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:11pt;color:rgb(0,0,0)">
Q_DECLARE_METATYPE(MyClass)<br>
<br>
</div>
<div style="font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:11pt;color:rgb(0,0,0)">
<br>
</div>
<div style="text-align:left;margin:0px;font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:11pt;color:rgb(0,0,0)">
Naturally, I tried invoking the qRegisterMetaType as well, with similar results. What am I doing wrong? Do these macros exist in PyQt5 (version 5.15.6)<br>
<br>
Thank you in advance,</div>
<div style="text-align:left;margin:0px;font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:11pt;color:rgb(0,0,0)">
Tassos</div>
<div id="m_-3264423711009482241Signature" style="color:inherit"></div>
</div>

</div></blockquote></div>