Combining pyqtEnum and pyqtProperty
Phil Thompson
phil at riverbankcomputing.com
Wed Dec 14 18:25:46 GMT 2022
On 08/12/2022 03:45, Arthur Gordon-Wright wrote:
> 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!
Should be fixed in the next PyQt6 snapshot.
Thanks,
Phil
-------------- 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/20221214/be14ef2a/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/20221214/be14ef2a/attachment-0001.obj>
More information about the PyQt
mailing list