In this article we will see how we can make a combo box who have check-able items. By default when we create a combo box its items are not check-able i.e we can select any one item at a time although we can create such combo box by editing the combo box class. Below is the representation of how check-able combo box look like.
In order to do this we have to make a new editable combo box class which inherits the combo box and adds a new feature of check able combo box, below is the syntax of new class
class CheckableComboBox(QComboBox): def __init__(self, parent = None): super(CheckableComboBox, self).__init__(parent) self.view().pressed.connect(self.handleItemPressed) self.setModel(QStandardItemModel(self)) def handleItemPressed(self, index): item = self.model().itemFromIndex(index) if item.checkState() == Qt.Checked: item.setCheckState(Qt.Unchecked) else: item.setCheckState(Qt.Checked)
Below is the implementation –
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course