[PyQt] VBoxLayout help.

Barry Scott barry at barrys-emacs.org
Fri Mar 6 08:51:28 GMT 2020



> On 6 Mar 2020, at 07:25, Souvik Dutta Chowdhury <souvik.viksou at outlook.com> wrote:
> 
> I have a vbox layout which is my main layout. I have set a label to be the sole widget in my layout. I have not specified anything else except 
> self.vbox.addWidget(label)

> The problem is when the window is first run the label appears at the top most corner but then changes position to the middle of the page.

QVBoxLayout is documented here  https://doc.qt.io/qt-5/qvboxlayout.html <https://doc.qt.io/qt-5/qvboxlayout.html> says its a derived from
QBoxLayout  https://doc.qt.io/qt-5/qboxlayout.html <https://doc.qt.io/qt-5/qboxlayout.html> where the addWidget() call is documented.
addWidget has an alignment arg, I think that is what you are looking for.

> The change happens when I try to resize the window. Why is this happening and how to stop it?

The layouts cause the contained widgets to resize when the layout is resized. This is usually what you want.
If you really want to change the way resize works then override the resize (?) method on the widget.

> I even tried using a
> label.setGeometry(10, 10, 200, 200)

This is changed when the resize happens.

> The result is still the same.

Barry

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20200306/1e0f902e/attachment.htm>


More information about the PyQt mailing list