PyQt6 Tutorials
About Lesson

In this PyQt6 lesson we are going to learn about How to Create QCheckBox in PyQt6, first we will learn that how you can use coding for creating QCheckBox, after that we will use Qt Designer for creating QCheckBox in PyQt6.

 

 

This is the complete code for this lesson.

 

 

 

 

In this example we want to use two layouts first one is a QHBoxLayout, in the QHBoxLayout we want to add our three checkboxes.

 

 

You can use QCheckBox class for creating of the checkboxes, and you need to just add the title for the checkbox.

 

 

You can set the font size of QCheckBox using this code.

 

 

In here we have connected the toggled() signal of the QCheckBox with the item_selected() method that we will create.

 

 

Also you need to add your checkbox in the QHBoxLayout using this code.

 

 

In here we have created QVBoxLayout with QLabel.

 

 

And this is the method that we have already connected with toggled() signal of the checkbox. basically in this method we are going to check the value of the checkboxes.

 

 

 

Run the complete code and this is the result.

How to Create QCheckBox in PyQt6
How to Create QCheckBox in PyQt6

 

 

 

 

Now we want to use Qt Designer for creating of the QCheckBox, Open your Qt Designer, you can just write pyqt5designer in your terminal, after opening the Qt Designer you need to create QWidget window, now we need to add our widgets in Qt Designer.

  • Add three QCheckBox and make the layout horizontally
  • Add a QLabel, after that make the main window layout vertically
PyQt QCheckBox Qt Designer
PyQt QCheckBox Qt Designer

 

 

 

 

After completing the design you need to save the .ui file, iam going to name it CheckBox.ui, for converting you need to use pyuic6 module.  pyuic6 module is located in the Scripts folder of your Python installation, run this command for converting in your terminal.

 

 

 

This is the converted code.

 

 

 

We have added some new codes in our converted file, the first one is the toggled() signal for our QCheckBox, and we have connected this with the method.

 

 

 

And also this is the method that we have connected with the toggled() signal of pyqt6 checkbox.

 

 

 

 

Run the complete code and this is the result.

How to Create QCheckBox in PyQt6
How to Create QCheckBox in PyQt6

 

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