I was able to get this working by creating a subclass of QItemDelegate for the checkbox, then plugging that into the item delegate for the combobox. I didn’t use geometry but instead some random uuids to illustrate the point. Tested in Mari 3.3v1.
# Built in
from uuid import uuid4
# Third party
from PySide.QtCore import Qt
from PySide.QtGui import (
QComboBox,
QMainWindow,
QVBoxLayout,
QPushButton,
QItemDelegate,
QStandardItem,
QStandardItemModel
)
# Custom
ROWS = 10
class CheckBoxDelegate(QItemDelegate):
""" Check box delegate """
def __init__(self, parent=None):
""" Initialization """
super(CheckBoxDelegate, self).__init__(parent)
def createEditor(parent, op, idx):
""" Creates the checkbox """
self.editor = QCheckBox(parent)
class MainWin(QDialog):
""" Main window """
def __init__(self, parent=None):
""" Initialization """
super(MainWin, self).__init__(parent)
self.setWindowTitle('Test Window')
self.main_layout = QVBoxLayout()
self.setLayout(self.main_layout)
self.item_model = QStandardItemModel(ROWS, 1)
self.combobox = QComboBox()
self.checkboxdel = CheckBoxDelegate()
self.combobox.setItemDelegate(self.checkboxdel)
self.insert_test_data()
self.combobox.setModel(self.item_model)
self.main_layout.addWidget(self.combobox)
self.test_button = QPushButton('Print checked items')
self.test_button.clicked.connect(self.test_clicked)
self.main_layout.addWidget(self.test_button)
def insert_test_data(self):
""" Inserts test uuids into a combobox widget. """
for i in range(0, ROWS):
item = QStandardItem(str(uuid4()))
item.setCheckable(True)
item.setSelectable(False)
self.item_model.setItem(i, 0, item)
def test_clicked(self):
""" Prints info on checked items on click. """
for i in range(0, ROWS):
item = self.item_model.item(i, 0)
print(item.text(), item.checkState())
if __name__ == '__main__':
win = MainWin()
win.show()