Details
-
Bug
-
Resolution: Invalid
-
Not Evaluated
-
None
-
6.9.0
-
None
-
Python 3.13.2 (tags/v3.13.2:4f8bb39, Feb 4 2025, 15:23:48) [MSC v.1942 64 bit (AMD64)] on win32
PySide6 6.9.0
Windows 11
Description
(Maybe this is a documentation error not a code error? QWidget.sizeHint is marked as a "property" at https://doc.qt.io/qtforpython-6/PySide6/QtWidgets/QWidget.html#PySide6.QtWidgets.QWidget.sizeHint. However it is marked as a "const" at https://doc.qt.io/qt-6/qwidget.html#sizeHint-prop. Did I misunderstand anything?)
Minimal example
from PySide6.QtCore import QSize from PySide6.QtWidgets import QWidget, QApplication app = QApplication() widget = QWidget() widget.sizeHint = QSize(200, 112) widget.show() app.exec()
Output:
Traceback (most recent call last): File "d:\documents\temp4.py", line 7, in <module> widget.show() ~~~~~~~~~~~^^ TypeError: Error calling Python override of QWidget::1:sizeHint(): 'PySide6.QtCore.QSize' object is not callable
Additional findings
1. Before widget.show(), sizeHint works fine, behaving like a normal attribute.
from PySide6.QtCore import QSize from PySide6.QtWidgets import QWidget, QApplication app = QApplication() widget = QWidget() widget.sizeHint = QSize(200, 112) print(widget.sizeHint.width()) # 200 widget.sizeHint = 123 print(widget.sizeHint) # 123 widget.show() # ↑ TypeError: Error calling Python override of QWidget::1:sizeHint(): 'int' object is not callable app.exec()
2. If you set sizeHint to a function, it will really be called.
from PySide6.QtWidgets import QWidget, QApplication app = QApplication() widget = QWidget() widget.sizeHint = lambda: print("aaa") print("ok") widget.show() app.exec()
This code will show a window and produce the following output:
ok aaa <sys>:0: RuntimeWarning: Invalid return value in function 'QWidget.1:sizeHint', expected PySide6.QtCore.QSize, got NoneType.