PyQt5 Tutorial – Create CheckBox in Qt Designer

In this PyQt5 Tutorial we want to Create CheckBox in Qt Designer , for creating of CheckBox in PyQt5 we need to use QCheckBox class, In PyQt5 QCheckBox is a class that provides checkbox widget for use in graphical user interfaces (GUIs). checkbox i GUI component that allows the user to select or deselect a single option.

when checkbox is selected, it displays checkmark or an ‘X’ indicating that the option is enabled. when it is deselected, checkbox is empty indicating that the option is disabled.

QCheckBox is commonly used in GUIs to allow users to turn features on or off, to select items from a list or to indicate agreement with particular condition or statement.

In PyQt5 QCheckBox class inherits from QAbstractButton class, which provides basic functionality for all types of buttons in the Qt framework. QCheckBox class adds additional functionality specific to checkboxes, such as the ability to set and retrieve the state of the checkbox, and to respond to state changes.

 

 

Also you can watch different programming videos in Geekscoders

 

 

 

 

 

Open your Qt Designer, you can just write pyqt5designer in your terminal, after opening the Qt Designer you need to create Dialog without Buttons window. now we add widgets in Qt Designer.

  • First add a vertical or QVBoxLayout
  • Add QLabel with QHBoxLayout in the vertical layout 
  • in the QHBoxLayout you need to add a QLabel also a QVBoxLayout, and in the QVBoxLayout add three QCheckBox.
  • Also at the end you need to add another Label, it should be in your main QVBoxLayout.

 

 

 

This is the design that we want.

PyQt5 CheckBox Design
PyQt5 CheckBox Design

 

 

 

 

After completing the design you need to save your design, the extension will be .ui file. now it is time to convert our .ui file in to .py file. there are two ways that you can do, first way is loading the ui file, the second way is converting the .ui file to .py file, we want to use the second way. for converting of the ui file to python file we need to use pyuic5 module, this module is located in the Scripts folder of your python installation, you need to copy your ui file in the Scripts folder of your Python installation. after that open the terminal in the Scripts folder, and run this command.

 

 

 

 

And this is the converted file, also we have added a method in the code because we will connect the method with the stateChanged() signal of checkbox.

 

 

 

We have added some new codes in their so the first one is the stateChanged() signal for our QCheckBox. and we have connected this with the checked_item() method.

 

 

 

And also this is the method or slot that we have connected with the stateChanged() signal of pyqt5 checkbox. basically in this method we want to check our checkboxes state.

 

 

 

 

 

Run the complete code and this is the result 

PyQt5 Tutorial - Create CheckBox in Qt Designer
PyQt5 Tutorial – Create CheckBox in Qt Designer

Subscribe and Get Free Video Courses & Articles in your Email

 

1 thought on “PyQt5 Tutorial – Create CheckBox in Qt Designer”

Leave a Comment

Share via
Copy link
Powered by Social Snap
×