def paint(self, painter, option, index): checked = bool(index.data()) checkbox = QCheckBox() if (index.flags() & Qt.ItemIsEditable) > 0: checkbox.setEnabled(True) else: checkbox.setEnabled(False) # Implement tristate checkboxe for folder nodes if checked: checkbox.setCheckState(Qt.Checked) else: checkbox.setCheckState(Qt.Unchecked) if self.parent(): checkbox.setStyleSheet(self.parent().styleSheet()) width = option.widget.columnWidth(1) height = option.widget.rowHeight(0) painter.save() painter.translate(option.rect.topLeft()) checkbox.rect = option.rect checkbox.setFixedSize(width, height) checkbox.render(painter, QPoint(0, 0)) painter.restore()
def paint(self, painter, option, index): checked = bool(index.data()) checkbox = QCheckBox() if (index.flags() & Qt.ItemIsEditable) > 0: checkbox.setEnabled(True) else: checkbox.setEnabled(False) if checked: checkbox.setCheckState(Qt.Checked) else: checkbox.setCheckState(Qt.Unchecked) checkbox.rect = self.getCheckBoxRect(option) #checkbox.setCheckState(QStyle.State_Enabled) style = '''QCheckBox, QRadioButton { color: #546E7A; } QCheckBox::indicator::unchecked { background-color: #FFFFFF; border: 1px solid #536D79; } QCheckBox::indicator::checked, QTreeView::indicator::checked { background-color: qradialgradient(cx:0.5, cy:0.5, fx:0.25, fy:0.15, radius:0.3, stop:0 #80CBC4, stop:1 #FFFFFF); border: 1px solid #536D79; } QCheckBox::indicator:disabled, QRadioButton::indicator:disabled, QTreeView::indicator:disabled { background-color: #444444; /* Not sure what this looks like */ } QCheckBox::indicator::checked:disabled, QRadioButton::indicator::checked:disabled, QTreeView::indicator::checked:disabled { background-color: qradialgradient(cx:0.5, cy:0.5, fx:0.25, fy:0.15, radius:0.3, stop:0 #BBBBBB, stop:1 #444444); /* Not sure what this looks like */ } ''' checkbox.setStyleSheet(style) painter.save() painter.translate(option.rect.topLeft()) checkbox.render(painter, QPoint(0, 0)) painter.restore()