PDA

View Full Version : Would like to know how to add a Checkbox as an item to a combo Box



koushik
8th March 2011, 04:21
Hi All,

I'm using PyQT as my toolkit for my GUI Development and I have a requirement to add checkboxes as items of a combo box. I would like to know how to achieve this. I tried searching but no luck so far. so just thought of seeking your help.

Folloiwng is the code that I have written.

class CheckboxInsideListbox(QWidget):
def __init__(self, parent = None):
super(CheckboxInsideListbox, self).__init__(parent)
self.setGeometry(250,250,300,300)
self.MainUI()

def MainUI(self):
#stb_label = QLabel("Select STB\'s")
stb_combobox = QComboBox()
length = 10
cb_layout = QVBoxLayout(stb_combobox)
for i in range(length):
c = QCheckBox("STB %i" % i)
cb_layout.addWidget(c)

main_layout = QVBoxLayout()
main_layout.addWidget(stb_combobox)
main_layout.addLayout(cb_layout)
self.setLayout(main_layout)

wysota
8th March 2011, 12:12
Set a model on the combobox that will handle CheckStateRole. Then disable the popup flag from combobox's popup.