[PySide] PySide6 true_property

Cristián Maureira-Fredes Cristian.Maureira-Fredes at qt.io
Mon Aug 9 20:24:23 CEST 2021


On 8/9/21 5:07 PM, paolo at paolodestefani.it wrote:
> Hello list
> I'm new to pyside but i played a lot with pyqt5 in the last few years.
> I'm trying to port to pyside6 a simple application using snake_case and 
> true_property new options
> 
> But I immediately got stuck in this simple problem: how to set the 
> geometry of a widget ?
> Before i used widget.setGeometry(10, 10, 50, 50) but how to do this with 
> true_property ?
> 
> from PySide6.QtWidgets import QApplication, QWidget
> from PySide6 import QtCore
> from __feature__ import true_property
> app = QApplication([])
> w = QWidget()
> w.geometry = 10, 10, 50, 50
> Traceback (most recent call last):
>    Python Shell, prompt 6, line 1
> builtins.TypeError: 'PySide6.QtWidgets.QWidget.geometry.fset' called 
> with wrong argument types:
>    PySide6.QtWidgets.QWidget.geometry.fset(tuple)
> Supported signatures:
>    PySide6.QtWidgets.QWidget.geometry.fset(PySide6.QtCore.QRect)
>    PySide6.QtWidgets.QWidget.geometry.fset(int, int, int, int)
> 
> How can i use the second sopported signature if not passing a tuple ?
> 
> -- 
> Paolo De Stefani


Hey Paolo,

the issue lies on the nature of the setGeometry(x, y, w, h) function,
since it's just an overload that inside the code calls:
setGeometry(QtCore.QRect(x, y, w, h)), so it was designed
just for convenience.

The 'geometry' property *is* a QRect element,
so that's why one cannot assign a tuple, but a QRect object,
so for your specific case, you need to replace

 >>> w.geometry = 10, 10, 50, 50

by

 >>> w.geometry = QtCore.QRect(10, 10, 50, 50)

It doesn't sound too convenient,
but sadly it's the origin of the property itself,
which depends on a QRect element.

If you believe that accepting a tuple as a value
for the 'geometry' property is a valid use case,
that has even some positive effect in other sides
of PySide, feel free to open an issue on JIRA
https://bugreports.qt.io/projects/PYSIDE
so we can discuss on how difficult would it be
to implement and adapt the current bindings
for that use case.

Cheers!

-- 
Dr. Cristián Maureira-Fredes
R&D Manager

The Qt Company GmbH
Erich-Thilo-Str. 10
D-12489 Berlin

Geschäftsführer: Mika Pälsi,
Juha Varelius, Jouni Lintunen
Sitz der Gesellschaft: Berlin,
Registergericht: Amtsgericht
Charlottenburg, HRB 144331 B


More information about the PySide mailing list