[PySide] setLayout and setCentralWidget when using true_property

Matt Milner milner94 at live.co.uk
Sun Nov 20 02:50:10 CET 2022

Hi all,

I have been attempting to port a small app from PyQt6 to PySide6, in part in order to use the more pythonic syntax enabled recently by:

from __feature__ import true_property, snake_case

Changing the syntax took a while but was eventually sorted. However, running the program resulted in a window appearing with the correct name but no widgets whatsoever. Diagnosing the issue took me quite a while but in the end I figured out that to set the layout of a widget and then make it the central widget it is apparently required to write:

class MainWindow(QMainWindow):
    def __init__(self):
        main_layout = QVBoxLayout()
layout_widget = QWidget()

However, given that setter/getter methods of the form setText(info) has become set_text = info, I expected the syntax for setting a layout or central widget to be analogous i.e.:
        layout_widget.layout = main_layout
        self.central_widget = layout_widget

Is this intended behaviour or an oversight? If intended, why should setting a layout/widget be different to setting text or setting a widget to be enabled?

Kind regards,

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20221120/f4491dc5/attachment.htm>

More information about the PySide mailing list