PySide6: Why QSpacerItem uses kwargs [hv]Data instead of [hv]Policy?
-
Could this be some sort of a bug? Or is it just undocumented/hard to find change?
Got an error saying
AttributeError: PySide6.QtWidgets.QSpacerItem.__init__(): unsupported keyword 'hPolicy'
, so checked Qt6 doc for changes, but everything seemed fine. After checking PySide6 doc it turned out that keyword args [hv]Policy were specified as [hv]Data in call signature, yet doc body still mentioned [hv]Policy...Update.
Damn... The same happened with PySide6.QtGui.PySide6.QtGui.QPixmap.scaled:
aspectRatioMode
isaspectMode
andtransformMode
ismode
... -
Sorry it took so long...
pip install PySide6==6.0.1
PySide6.QtWidgets.QSpacerItem:
from PySide6.QtWidgets import QSpacerItem, QSizePolicy QSpacerItem(0, 0, hPolicy = QSizePolicy.Expanding) QSpacerItem(0, 0, vPolicy = QSizePolicy.Fixed)
PySide6.QtGui.QPixmap.scaled:
from PySide6.QtCore import Qt, QSize from PySide6.QtGui import QPixmap from PySide6.QtWidgets import QApplication app = QApplication() QPixmap().scaled(QSize(640, 480), aspectRatioMode=Qt.IgnoreAspectRatio) QPixmap().scaled(QSize(640, 480), transformMode=Qt.FastTransformation) app.exec_()
In both cases
AttributeError: PySide6.{module}.{class}.{method}(): unsupported keyword '{kwarg}'
is raised. -
@anonyumu It seems that it is a PySide6 bug that has changed the name of the kwargs, for example using
help
you get the names of the kwargs:dir(QSpacerItem)
output
Help on class QSpacerItem in module PySide6.QtWidgets: class QSpacerItem(QLayoutItem) | QSpacerItem(self, w: int, h: int, hData: PySide6.QtWidgets.QSizePolicy.Policy = PySide6.QtWidgets.QSizePolicy.Policy.Minimum, vData: PySide6.QtWidgets.QSizePolicy.Policy = PySide6.QtWidgets.QSizePolicy.Policy.Minimum) -> None | | QSpacerItem(self, w: int, h: int, hData: PySide6.QtWidgets.QSizePolicy.Policy = PySide6.QtWidgets.QSizePolicy.Policy.Minimum, vData: PySide6.QtWidgets.QSizePolicy.Policy = PySide6.QtWidgets.QSizePolicy.Policy.Minimum) -> None | | Method resolution order: | QSpacerItem | QLayoutItem | Shiboken.Object | builtins.object | | Methods defined here: | | __delattr__(self, name, /) | Implement delattr(self, name). | | __init__(self, w: int, h: int, hData: PySide6.QtWidgets.QSizePolicy.Policy = PySide6.QtWidgets.QSizePolicy.Policy.Minimum, vData: PySide6.QtWidgets.QSizePolicy.Policy = PySide6.QtWidgets.QSizePolicy.Policy.Minimum) -> None | __init__(self, w: int, h: int, hData: PySide6.QtWidgets.QSizePolicy.Policy = PySide6.QtWidgets.QSizePolicy.Policy.Minimum, vData: PySide6.QtWidgets.QSizePolicy.Policy = PySide6.QtWidgets.QSizePolicy.Policy.Minimum) -> None | | Initialize self. See help(type(self)) for accurate signature. | | __setattr__(self, name, value, /) | Implement setattr(self, name, value). | | changeSize(self, w: int, h: int, hData: PySide6.QtWidgets.QSizePolicy.Policy = PySide6.QtWidgets.QSizePolicy.Policy.Minimum, vData: PySide6.QtWidgets.QSizePolicy.Policy = PySide6.QtWidgets.QSizePolicy.Policy.Minimum) -> None | changeSize(self, w: int, h: int, hData: PySide6.QtWidgets.QSizePolicy.Policy = PySide6.QtWidgets.QSizePolicy.Policy.Minimum, vData: PySide6.QtWidgets.QSizePolicy.Policy = PySide6.QtWidgets.QSizePolicy.Policy.Minimum) -> None | | expandingDirections(self) -> PySide6.QtCore.Qt.Orientations | expandingDirections(self) -> PySide6.QtCore.Qt.Orientations | | geometry(self) -> PySide6.QtCore.QRect | geometry(self) -> PySide6.QtCore.QRect | | isEmpty(self) -> bool | isEmpty(self) -> bool | | maximumSize(self) -> PySide6.QtCore.QSize | maximumSize(self) -> PySide6.QtCore.QSize | | minimumSize(self) -> PySide6.QtCore.QSize | minimumSize(self) -> PySide6.QtCore.QSize | | setGeometry(self, arg__1: PySide6.QtCore.QRect) -> None | setGeometry(self, arg__1: PySide6.QtCore.QRect) -> None | | sizeHint(self) -> PySide6.QtCore.QSize | sizeHint(self) -> PySide6.QtCore.QSize | | sizePolicy(self) -> PySide6.QtWidgets.QSizePolicy | sizePolicy(self) -> PySide6.QtWidgets.QSizePolicy | | spacerItem(self) -> PySide6.QtWidgets.QSpacerItem | spacerItem(self) -> PySide6.QtWidgets.QSpacerItem | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) from Shiboken.ObjectType | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from QLayoutItem: | | alignment(self) -> PySide6.QtCore.Qt.Alignment | alignment(self) -> PySide6.QtCore.Qt.Alignment | | controlTypes(self) -> PySide6.QtWidgets.QSizePolicy.ControlTypes | controlTypes(self) -> PySide6.QtWidgets.QSizePolicy.ControlTypes | | hasHeightForWidth(self) -> bool | hasHeightForWidth(self) -> bool | | heightForWidth(self, arg__1: int) -> int | heightForWidth(self, arg__1: int) -> int | | invalidate(self) -> None | invalidate(self) -> None | | layout(self) -> PySide6.QtWidgets.QLayout | layout(self) -> PySide6.QtWidgets.QLayout | | minimumHeightForWidth(self, arg__1: int) -> int | minimumHeightForWidth(self, arg__1: int) -> int | | setAlignment(self, a: PySide6.QtCore.Qt.Alignment) -> None | setAlignment(self, a: PySide6.QtCore.Qt.Alignment) -> None | | widget(self) -> PySide6.QtWidgets.QWidget | widget(self) -> PySide6.QtWidgets.QWidget | | ---------------------------------------------------------------------- | Data descriptors inherited from QLayoutItem: | | align | | ---------------------------------------------------------------------- | Methods inherited from Shiboken.Object: | | __getattribute__(self, name, /) | Return getattr(self, name). | | ---------------------------------------------------------------------- | Data descriptors inherited from Shiboken.Object: | | __dict__
Considering the above then the solution is:
QSpacerItem(0, 0, hData = QSizePolicy.Expanding) QSpacerItem(0, 0, vData = QSizePolicy.Fixed)
Same for scaled:
help(QPixmap.scaled)
Help on method_descriptor: scaled(...) scaled(self, s: PySide6.QtCore.QSize, aspectMode: PySide6.QtCore.Qt.AspectRatioMode = PySide6.QtCore.Qt.AspectRatioMode.IgnoreAspectRatio, mode: PySide6.QtCore.Qt.TransformationMode = PySide6.QtCore.Qt.TransformationMode.FastTransformation) -> PySide6.QtGui.QPixmap scaled(self, w: int, h: int, aspectMode: PySide6.QtCore.Qt.AspectRatioMode = PySide6.QtCore.Qt.AspectRatioMode.IgnoreAspectRatio, mode: PySide6.QtCore.Qt.TransformationMode = PySide6.QtCore.Qt.TransformationMode.FastTransformation) -> PySide6.QtGui.QPixmap
then
QPixmap().scaled(QSize(640, 480), aspectMode=Qt.AspectRatioMode.IgnoreAspectRatio) QPixmap().scaled(QSize(640, 480), mode=Qt.TransformationMode.FastTransformation)