Details
-
Bug
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
6.8.2, 6.8.3
-
None
-
Windows 11 (though almost certainly cross-platform)
Description
Bug Description
When setting a property that is an Enum type using the QObject.setProperty() method, the setProperty() method will fail unless an integer is passed into the function. This primarily causes issues with pyside6-uic generated code for custom widgets.
Example
Seen in the simple example below, setting the property using the (correct) enumeration fails and does not change anything unless casting to int first.
from PySide6.QtWidgets import QWidget widget = QWidget() result = widget.setProperty("focusPolicy", Qt.FocusPolicy.ClickFocus) print(widget.focusPolicy()) # Prints '0' (Representing Qt.FocusPolicy.NoFocus) print(result) # Prints 'False' as it failed to set the property result = widget.setProperty("focusPolicy", int(Qt.FocusPolicy.ClickFocus)) print(widget.focusPolicy()) # Prints '2' (Representing Qt.FocusPolicy.ClickFocus) print(result) # Prints 'True' as it successfully set the property
This occurs for seemingly every Qt enumeration. While wrapping the enumeration in an int is a hacky but easily workable solution for hand-written code, this primarily causes issues for pyside6-uic as it uses the setProperty method to set properties for custom widgets and does not wrap the Enumerations in ints. This then causes issues as the compiled UI file will not correctly set properties.
Current workarounds
Until this is resolved, the most obvious workarounds are to either post-process the code generated by pyside6-uic to wrap Enums with an integer value, or to set these values after creating the widget with the former being more reliable.
Potential solutions
A simple solution that would solve the immediate issue of the pyside6-uic generating the incorrect code is for pyside6-uic to wrap all generated enums with an int and could act as a quick-stop solution that would solve the immediate problems.
However, a more robust solution would be to fix the setProperty() method directly so that it can manage enumerations.
(Potentially) Related Links
- https://stackoverflow.com/questions/12609894/qt-q-enum-property-from-qvariantqulonglong - Could be related and likely shows at least the C++ code where setProperty() is managed however this is more likely an unrelated issue with how it manages non-int QVariants. That said, I couldn't seem to find a similar reference to the issue
Attachments
Issue Links
- relates to
-
PYSIDE-2840 Enum properties unsupported in Qt Designer custom widgets
-
- Closed
-