pythonpython-3.xpyqtpyqt5qgridlayout

How do setColumnStretch and setRowStretch work?


I have an application built using PySide2 which uses setColumnStretch for column stretching and setRowStretch for row stretching. It works well and good, but I am unable to understand how it is working. I am stuck on the two values inside those parentheses.

For example:

glay = QtWidgets.QGridLayout(right_container)
glay.addWidget(lineedit, 0, 0)
glay.addWidget(button2, 0, 2)

glay.addWidget(widget, 2, 0, 1, 3)  

glay.addWidget(button, 4, 0)                                    
glay.addWidget(button1, 4, 2)

glay.setColumnStretch(1, 1)                                     # setColumnStretch
glay.setRowStretch(1, 1)                                        # setRowStretch
glay.setRowStretch(2, 2)                                        # setRowStretch
glay.setRowStretch(3, 1)                                        # setRowStretch

This produces the output as shown in the image below:

image

But how? What does these four values inside glay.addWidget(widget, 2, 0, 1, 3)do? Please explain me all this with examples.


Solution

  • Short Answer: Read the Qt docs: https://doc.qt.io/qt-5/qgridlayout.html as it is clear and precise.

    Long Answer: