Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ToggleButtonDelegate(QtWidgets.QStyledItemDelegate):
- def paint(self, painter, option, index):
- value = index.data(QtCore.Qt.EditRole)
- state = QtWidgets.QStyle.State_On if value else QtWidgets.QStyle.State_Off
- checkbox_indicator = QtWidgets.QStyleOptionButton()
- checkbox_indicator.state |= QtWidgets.QStyle.State_Enabled
- checkbox_indicator.state |= state
- checkbox_indicator.rect = QtWidgets.QApplication.style().subElementRect(QtWidgets.QStyle.SE_CheckBoxIndicator, checkbox_indicator, None)
- x = option.rect.center().x() - checkbox_indicator.rect.width() / 2
- y = option.rect.center().y() - checkbox_indicator.rect.height() / 2
- checkbox_indicator.rect.moveTo(x, y)
- #if option.state:
- #painter.fillRect(option.rect, option.palette.highlight())
- QtWidgets.QApplication.style().drawControl(QtWidgets.QStyle.CE_CheckBox, checkbox_indicator, painter)
- def createEditor(self, parent, option, index):
- """Editor for templates and tasks."""
- index.model().setData(index, not index.data())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement