<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Qt Designer: Display a List of Enum Options in Custom Widget Properties Editor Using Python]]></title><description><![CDATA[<p dir="auto">I'm working on creating a custom widget for Qt Designer in Python using PyQt or PySide. I want to expose an enum property in the Qt Designer property editor, so that users can select from a list of predefined options rather than typing in arbitrary values.</p>
<p dir="auto">In C++, it is possible to expose an enum to Qt Designer using Q_ENUMS and Q_PROPERTY, as described in this <a href="https://stackoverflow.com/questions/49172604/qt-custom-widget-plugin-q-property-with-enum" target="_blank" rel="noopener noreferrer nofollow ugc">Stack Overflow question</a>.</p>
<p dir="auto">I want to achieve the same result in Python. Specifically, I want to:</p>
<ul>
<li>Define an enum in Python that can be used as a property in my custom widget.</li>
<li>Ensure that this enum is displayed as a dropdown list in the Qt Designer property editor.</li>
</ul>
<p dir="auto">Here's an outline of what I have so far:</p>
<pre><code class="language-python">
from qtpy.QtCore import Qt, QEasingCurve, QPropertyAnimation, QSize, Property, QPoint, QEnum
from qtpy.QtWidgets import QCheckBox, QApplication, QLabel
from enum import Enum

class EasingCurveEnum(Enum):
    Option1 = 0
    Option2 = 1
    Option3 = 2

class QCustomCheckBox(QCheckBox):
    def __init__(self, parent=None):
        super().__init__(parent)
        self._easing_curve = EasingCurveEnum.Option1
        # ...

    @Property(EasingCurveEnum, designable=True)
    def animationEasingCurve(self):
        return self._easing_curve
    
    @animationEasingCurve.setter
    def animationEasingCurve(self, curve):
        self._easing_curve = curve

</code></pre>
<p dir="auto">How can I make the EasingCurveEnum property appear as a list of options in the Qt Designer property editor?</p>
<p dir="auto"><strong>I've successfully registered my custom widget in Qt Designer, but the enum list property is not appearing.</strong></p>
<p dir="auto">Any guidance or examples would be greatly appreciated!</p>
<p dir="auto">Thanks in advance!</p>
<p dir="auto">If solution found, please share it here <a href="https://stackoverflow.com/q/78925082/12120839" target="_blank" rel="noopener noreferrer nofollow ugc">Stackoverflow post</a></p>
]]></description><link>https://forum.qt.io/topic/158463/qt-designer-display-a-list-of-enum-options-in-custom-widget-properties-editor-using-python</link><generator>RSS for Node</generator><lastBuildDate>Sun, 30 Aug 2026 21:08:12 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/158463.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 29 Aug 2024 12:46:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Qt Designer: Display a List of Enum Options in Custom Widget Properties Editor Using Python on Wed, 22 Jul 2026 23:44:20 GMT]]></title><description><![CDATA[<p dir="auto">Coming back (after 2 years ! ) to close this out, since I finally have a solution that's held up in production.</p>
<p dir="auto"><strong>Short answer: you can't get a real inline dropdown in Designer's Property Editor from pure Python.</strong> That specific bit needs a compiled C++ plugin. But there's a Python path that works well in practice — I'll explain both.</p>
<p dir="auto"><strong>What doesn't work (so you can skip the dead-ends I hit):</strong></p>
<p dir="auto">I tried a <code>QDesignerPropertySheetExtension</code> to swap the property's editor. On PySide6 6.11:</p>
<ul>
<li>You can't delegate to Designer's built-in sheet — <code>extensionManager().extension(...)</code> hands it back as a bare <code>QObject</code> and shiboken can't recover the real interface, so the methods just aren't there.</li>
<li>Replacing the sheet wholesale with a Python-built one <strong>segfaults Designer during form load</strong> — even when every property returns a plain string. Its core assumes the internal C++ sheet.</li>
</ul>
<p dir="auto">Also worth knowing: declaring the property as a <code>Q_ENUM</code>/<code>@QEnum</code> <em>does</em> give you a dropdown, but only for <strong>static, compile-time</strong> enums baked into the widget. It's no help if your options are computed at runtime (mine come from a project file), which was the whole point.</p>
<p dir="auto"><strong>What actually works — a task-menu extension:</strong></p>
<p dir="auto">Right-click the widget → your action pops a combo box → you write the choice back through the form cursor. It's undo-aware, dirties the form, and saves to the <code>.ui</code> like any normal edit.</p>
<pre><code class="language-python">from PySide6.QtDesigner import (QExtensionFactory, QPyDesignerTaskMenuExtension,
                                QDesignerFormWindowInterface)
from PySide6.QtGui import QAction
from PySide6.QtWidgets import QInputDialog

TASKMENU_IID = "org.qt-project.Qt.Designer.TaskMenu"

class ThemeTaskMenu(QPyDesignerTaskMenuExtension):
    def __init__(self, widget, parent=None):
        super().__init__(parent)
        self._widget = widget
        self._action = QAction("Set theme…", self)
        self._action.triggered.connect(self._choose)

    def taskActions(self):
        return [self._action]

    def _choose(self):
        names = ["Light", "Dark", "Solarized"]      # build this list at runtime
        current = self._widget.property("appTheme") or ""
        i = names.index(current) if current in names else 0
        name, ok = QInputDialog.getItem(self._widget.window(),
                                        "Theme", "Theme:", names, i, False)
        if not ok or not name:
            return
        fw = QDesignerFormWindowInterface.findFormWindow(self._widget)
        # cursor path = undoable + saved to the .ui; a raw setProperty won't stick
        (fw.cursor().setWidgetProperty(self._widget, "appTheme", name)
         if fw else self._widget.setProperty("appTheme", name))

class ThemeTaskMenuFactory(QExtensionFactory):
    def createExtension(self, obj, iid, parent):
        if iid != TASKMENU_IID or not isinstance(obj, MyCustomWidget):
            return None
        return ThemeTaskMenu(obj, parent)
</code></pre>
<p dir="auto">Register it in your plugin's <code>initialize(core)</code>:</p>
<pre><code class="language-python">core.extensionManager().registerExtensions(
    ThemeTaskMenuFactory(core.extensionManager()), TASKMENU_IID)
</code></pre>
<p dir="auto">Two things that bit me:</p>
<ul>
<li><strong>Apply via <code>fw.cursor().setWidgetProperty(...)</code></strong>, not just <code>widget.setProperty(...)</code> — otherwise the change never makes it into the saved <code>.ui</code>.</li>
<li>Keep the underlying property a plain, validated <code>@Property(str)</code>. The menu is only an input aid; the stored value stays portable and works fine on machines without your plugin.</li>
<li>If you have both PyQt5 and PySide6 installed, launch designer with <code>QT_API=pyside6</code> or qtpy may pick PyQt5 and your plugin import will fail.</li>
</ul>
<p dir="auto">So: static enum → <code>Q_ENUM</code>. Runtime options → task-menu extension. True inline dropdown → C++ only.</p>
<p dir="auto">I use a slightly fancier version of this (a little dock with a combo per property) in my widgets library if anyone wants a fuller reference:<br />
<a href="https://github.com/SpinnCompany/QT-PyQt-PySide-Custom-Widgets" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/SpinnCompany/QT-PyQt-PySide-Custom-Widgets</a></p>
<p dir="auto">Marking this solved — hope it saves someone the segfault hunt.</p>
]]></description><link>https://forum.qt.io/post/839323</link><guid isPermaLink="true">https://forum.qt.io/post/839323</guid><dc:creator><![CDATA[Khamisi Kibet]]></dc:creator><pubDate>Wed, 22 Jul 2026 23:44:20 GMT</pubDate></item><item><title><![CDATA[Reply to Qt Designer: Display a List of Enum Options in Custom Widget Properties Editor Using Python on Thu, 19 Jun 2025 05:08:40 GMT]]></title><description><![CDATA[<p dir="auto">Hello, is there any update for this issue? I'm also facing the problem that the QEnums properties are not loaded by QtDesigner</p>
]]></description><link>https://forum.qt.io/post/827868</link><guid isPermaLink="true">https://forum.qt.io/post/827868</guid><dc:creator><![CDATA[danielhrisca]]></dc:creator><pubDate>Thu, 19 Jun 2025 05:08:40 GMT</pubDate></item><item><title><![CDATA[Reply to Qt Designer: Display a List of Enum Options in Custom Widget Properties Editor Using Python on Thu, 29 Aug 2024 17:40:26 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/pl45m4">@<bdi>Pl45m4</bdi></a>  <a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a><br />
Thank you all for your feedback. I read these documentations <a href="https://doc.qt.io/qtforpython-6/PySide6/QtCore/QEnum.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qtforpython-6/PySide6/QtCore/QEnum.html</a> , <a href="https://doc.qt.io/qtforpython-6.5/PySide6/QtCore/QEnum.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qtforpython-6.5/PySide6/QtCore/QEnum.html</a> , tried different examples but they didn't work.</p>
<p dir="auto">I also attempted the example below which didn't work as I expected:</p>
<pre><code class="language-python">
class QCustomCheckBox(QCheckBox):
    @QEnum
    class EasingCurveEnum(Enum):
        Option1 = 0
        Option2 = 1
        Option3 = 2  
        
    def __init__(self, parent=None):
        super().__init__(parent)

        self._easing_curve = EasingCurveEnum.Option1
        # ...

    @Property(EasingCurveEnum, designable=True)
    def animationEasingCurve(self):
        return self._easing_curve
    
    @animationEasingCurve.setter
    def animationEasingCurve(self, curve):
        self._easing_curve = curve
</code></pre>
<p dir="auto">Images showing my custom properties:</p>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/23a82291-9648-437e-bd48-0974af7fe8fb.png" alt="Screenshot 2024-08-29 103702.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/01ac068f-3a41-4e88-8849-76c8c5ce5517.png" alt="Screenshot 2024-08-29 103626.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.qt.io/post/808354</link><guid isPermaLink="true">https://forum.qt.io/post/808354</guid><dc:creator><![CDATA[Khamisi Kibet]]></dc:creator><pubDate>Thu, 29 Aug 2024 17:40:26 GMT</pubDate></item><item><title><![CDATA[Reply to Qt Designer: Display a List of Enum Options in Custom Widget Properties Editor Using Python on Thu, 29 Aug 2024 17:18:07 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/khamisi-kibet">@<bdi>Khamisi-Kibet</bdi></a></p>
<p dir="auto">Your enum needs to be part of a <code>QObject</code> based class... otherwise moc / QtDesigner won't notice it.<br />
Check the indentation in my linked example. It's part of the <code>QObject</code> class, not a standalone Python enum class.</p>
<p dir="auto">Edit:<br />
What <a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> wrote above :D</p>
]]></description><link>https://forum.qt.io/post/808353</link><guid isPermaLink="true">https://forum.qt.io/post/808353</guid><dc:creator><![CDATA[Pl45m4]]></dc:creator><pubDate>Thu, 29 Aug 2024 17:18:07 GMT</pubDate></item><item><title><![CDATA[Reply to Qt Designer: Display a List of Enum Options in Custom Widget Properties Editor Using Python on Thu, 29 Aug 2024 17:17:47 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/khamisi-kibet">@<bdi>Khamisi-Kibet</bdi></a><br />
Please read <a class="plugin-mentions-user plugin-mentions-a" href="/user/pl45m4">@<bdi>Pl45m4</bdi></a>'s link and the sample there:</p>
<blockquote>
<p dir="auto">The enumerator must be in a QObject derived class to be registered.</p>
</blockquote>
<p dir="auto">I know no more than that, nor whether this is the right approach.  Try moving your <code>class EasingCurveEnum(Enum)</code> inside <code>class QCustomCheckBox(QCheckBox)</code>.</p>
]]></description><link>https://forum.qt.io/post/808352</link><guid isPermaLink="true">https://forum.qt.io/post/808352</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Thu, 29 Aug 2024 17:17:47 GMT</pubDate></item><item><title><![CDATA[Reply to Qt Designer: Display a List of Enum Options in Custom Widget Properties Editor Using Python on Thu, 29 Aug 2024 17:05:39 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/pl45m4">@<bdi>Pl45m4</bdi></a><br />
Am assuming that you're referring to this:</p>
<pre><code class="language-python">@QEnum
class EasingCurveEnum(Enum):
....
</code></pre>
<p dir="auto">I tried it didnt work.</p>
<p dir="auto">I also tried this, did not work either:</p>
<pre><code class="language-python">
class EasingCurveEnum(Enum):
    Option1 = 0
    Option2 = 1
    Option3 = 2

class QCustomCheckBox(QCheckBox):
    def __init__(self, parent=None):
        super().__init__(parent)
        
         #tried.....
        QEnum(EasingCurveEnum)

        self._easing_curve = EasingCurveEnum.Option1
        # ...

    @Property(EasingCurveEnum, designable=True)
    def animationEasingCurve(self):
        return self._easing_curve
    
    @animationEasingCurve.setter
    def animationEasingCurve(self, curve):
        self._easing_curve = curve


</code></pre>
]]></description><link>https://forum.qt.io/post/808351</link><guid isPermaLink="true">https://forum.qt.io/post/808351</guid><dc:creator><![CDATA[Khamisi Kibet]]></dc:creator><pubDate>Thu, 29 Aug 2024 17:05:39 GMT</pubDate></item><item><title><![CDATA[Reply to Qt Designer: Display a List of Enum Options in Custom Widget Properties Editor Using Python on Thu, 29 Aug 2024 13:41:57 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/khamisi-kibet">@<bdi>Khamisi-Kibet</bdi></a></p>
<p dir="auto">I guess the same way as in C++. You need to register the enum.</p>
<p dir="auto">When using Python enums, with <code>@QEnum</code></p>
<ul>
<li><a href="https://doc.qt.io/qtforpython-6/PySide6/QtCore/QEnum.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qtforpython-6/PySide6/QtCore/QEnum.html</a></li>
</ul>
]]></description><link>https://forum.qt.io/post/808337</link><guid isPermaLink="true">https://forum.qt.io/post/808337</guid><dc:creator><![CDATA[Pl45m4]]></dc:creator><pubDate>Thu, 29 Aug 2024 13:41:57 GMT</pubDate></item></channel></rss>