Search code examples
pythonpysidepyside6

true_property and snake_case breaking property-keyword widget constructors in PySide6


I'm encountering an issue trying to use true_property and/or snake_case in PySide6. Without either, I can construct widgets using a form like this:

text = QtWidgets.QLabel('Example', margin=10)

where I specify Qt properties as keyword arguments when creating the widget. This does the same thing as:

text = QtWidgets.QLabel('Example', margin=10)
text.setMargin(10)
# Or with snake_case:
text.set_margin(10)
# Or with true_property:
text.margin = 10

However, importing snake_case and/or true_property breaks this "shortcut" constructor. I get the following results:

from PySide6 import QtWidgets
from __feature__ import snake_case

app = QtWidgets.QApplication()
text = QtWidgets.QLabel('Example', margin=10)

# AttributeError: PySide6.QtWidgets.QLabel.__init__(): 'margin' is not a Qt property or a signal
from PySide6 import QtWidgets
from __feature__ import true_property
# Same results from either of these:
# from __feature__ import snake_case, true_property
# from __feature__ import true_property, snake_case

app = QtWidgets.QApplication()
text = QtWidgets.QLabel('Example', margin=10)

# Segmentation fault: 11

Is this a bug, or is there something I'm missing here?

Do I really have to choose between these ergonomic Pythonifications and convenient constructors, or is there a way to get them to work together?

What's causing this behavior?


Solution

  • This was indeed a bug in PySide, which I reported here: PYSIDE-1705.

    It has now been fixed as of PySide 6.2.4.