Course Content
PyQt5 Basics – Installation Process, Qt Designer Intro
In this part we are going to talk about some basics functionalities in PyQt5, we go through installation process, creating QPushButton, Signals and working with Qt Designer.
0/4
PyQt5 Tutorials
About Lesson

In this lesson we are going to learn How to Create VBoxLayout with PyQt5, basically there are different types of layout management that you can use in PyQt5.we have QVBoxLayout, QHBoxLayout and QGridLayout. particularly in this lesson we are talking about VBoxLayout, so by using vboxlayout  you can align your widgets vertically. we create our layout in two ways, the first way is that we can do by coding and the second way is by using Qt Designer

 

 

PyQt5 VBoxLayout by Coding 

First we need to import our required classes and the important one is our QVBoxLayout, using QVBoxLayout class we can align our widgets vertically.

 

 

These are used for creating title, icon and the geometry of the window, basically the geometry of the window is the x,y position, width and height of the window.

 

 

This is the place that we have created our QVBoxLayout object.

 

 

We are going to add four QPushButton in our VBoxLayout, first you need to create the object of QPushButton.

 

 

After creating of your buttons, you need to add the buttons in VBoxLayout. you can use addWidget() method.

 

 

Now you need to set the layout for the main window, if you don’t do this you will not see any widgets in your window.

 

 

So now this is the code for How to Create VBoxLayout in PyQt5

 

 

 

Run the complete code and this is the result 

PyQt5 VBoxLayout
PyQt5 VBoxLayout

 

 

PyQt5 VBoxLayout By Qt Designer

Now we want to create our layout using Qt Designer , so you need to open your Qt Designer, you can write pyqt5designer in your terminal, after opening create a new Widget window. and add four QPushButton, after that select all buttons and right click on them choose Layout and Layout Vertically.

Qt Designer Layout Vertically
Qt Designer Layout Vertically

 

After doing this your all widgets will be aligned vertically, also you need to do the same for the window, right click on the window and choose layout vertically,save your ui file, iam going to call it vboxlayout.ui , and copy the file in your working directory.

 

 

 

now we are going to load our ui file. make a new python file and call it LoadVBox.py. we are going to use uic module for loading our ui file.

 

 

 

Run the python code and this is the result.

How to Create VBoxLayout in PyQt5
How to Create VBoxLayout in PyQt5
Thank you for visiting my website! If you enjoyed the free courses, please consider supporting my works on Patreon.
Exercise Files
No Attachment Found
No Attachment Found