PyQt5 – Check box checked state depending upon another check box
Sometimes while creating a GUI(Graphical User Interface) application there is a need to make lot of check boxes, and some check box depend upon the previous check box for example there are two following check box first check box is “Do you have Laptop ?” and second check box is
“Your laptop has i7 Processor?” Here we can see that if first check box is true then only second check box can be true.
So in order to over come this dependency we have to stop the second check box to get checked if first check box is unchecked. When the first check box get checked then only user can check the second check box.
In order to do this we have to do the following:
1. Create two check boxes.
2. Set second check box check-able state to False i.e by default it can’t get checked.
3. Add action to first check box i.e when state of first check box changes call the associated method with it.
4. Inside the action method check if the first check box is checked.
5. If first check box is checked then make second check box check-able state to True i.e now it can get checked.
6. If first check box is unchecked make second check box state to uncheck and make it uncheck-able.
Below is the implementation.