I've been trying to scale a Pixmap image correctly, however when calling the function I get a TypeError - am I doing something wrong?
It's stating that "size" isn't a valid argument, but also stating it's an argument within the same error call.
Code:
label = QtWidgets.QLabel(self.main_window)
image = QtGui.QPixmap(assets.images.icon)
image = image.scaled(
size = QtCore.QSize(64, 64),
aspectRatioMode = QtCore.Qt.AspectRatioMode.KeepAspectRatio,
TransformationMode = QtCore.Qt.TransformationMode.SmoothTransformation
)
label.resize(QtCore.QSize(64, 64))
label.setPixmap(image)
Error:
arguments did not match any overloaded call:
scaled(self, size: QSize, aspectRatioMode: Qt.AspectRatioMode = Qt.IgnoreAspectRatio, transformMode: Qt.TransformationMode = Qt.FastTransformation): 'size' is not a valid keyword argument
transformMode
instead ofTransformationMode
, as given in the error message.size=
and just leaveQtCore.QSize(64, 64),
as a non-keyword argument; edit: ok, you found the solution👍key=value
), not positional ones. This applies to all native Qt class constructors and functions, but not for overrides of subclasses, as they're native Python functions and work as expected. Always check the documentation for argument signature, if arguments are positional, don't use them as named arguments. When in doubt, usehelp(<class or function>)
in the interactive python shell.