Combining pyqtEnum and pyqtProperty

Arthur Gordon-Wright agordonwright at gmail.com
Thu Dec 8 03:45:09 GMT 2022


Hi,

I have some code that defines an enum nested in a class, defines a
pyqtProperty using that enum, then uses the value of that to control a
stylesheet.

In PyQt5 5.15, I use the Q_ENUM macro to annotate the enum class after
defining it, and everything works fine. Changing the value of the
pyqtProperty after creating the widget then repolishing it causes the
colour to change. This works whether the property's class is an enum or
just a normal object.

In PyQt6 6.4 (and 6.3), I use pyqtEnum as a decorator on the enum class
(also tried using it afterwards in the same place I'd use Q_ENUM), and
while the widget initially appears to have the correct colour, it won't
change if I update the property.

(In both cases, I actually have to use enum.IntEnum, as I get a hardcrash
0xC0000409 during the polishing phase when using a normal Enum).

Perhaps I'm doing something wrong on the stylesheet, but I've tried every
possible syntax I can think of: using the enum member name, member value,
putting it in quotes or not etc.

I've attached two examples in PyQt5 and PyQt6, the only real difference
between them is in:

class ProgressBar(QProgressBar):
    class Status(enum.IntEnum):
        success = 0
        error = 1
    Q_ENUM(Status)

v.s.

class ProgressBar(QProgressBar):
    @pyqtEnum
    class Status(enum.IntEnum):
        success = 0
        error = 1

Any advice is much appreciated, can't work out if this is a bug or just me!

Cheers,
Arthur
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20221208/2d64b895/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main_qt5.py
Type: application/octet-stream
Size: 1317 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20221208/2d64b895/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main_qt6.py
Type: application/octet-stream
Size: 1314 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20221208/2d64b895/attachment-0001.obj>


More information about the PyQt mailing list