Advertisement
Guest User

Untitled

a guest
Sep 4th, 2022
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.11 KB | None | 0 0
  1. class ToggleButtonDelegate(QtWidgets.QStyledItemDelegate):
  2.  
  3.     def paint(self, painter, option, index):
  4.         value = index.data(QtCore.Qt.EditRole)
  5.         state = QtWidgets.QStyle.State_On if value else QtWidgets.QStyle.State_Off
  6.         checkbox_indicator = QtWidgets.QStyleOptionButton()
  7.         checkbox_indicator.state |= QtWidgets.QStyle.State_Enabled
  8.         checkbox_indicator.state |= state
  9.         checkbox_indicator.rect = QtWidgets.QApplication.style().subElementRect(QtWidgets.QStyle.SE_CheckBoxIndicator, checkbox_indicator, None)
  10.  
  11.         x = option.rect.center().x() - checkbox_indicator.rect.width() / 2
  12.         y = option.rect.center().y() - checkbox_indicator.rect.height() / 2
  13.         checkbox_indicator.rect.moveTo(x, y)
  14.        
  15.         #if option.state:
  16.             #painter.fillRect(option.rect, option.palette.highlight())
  17.  
  18.         QtWidgets.QApplication.style().drawControl(QtWidgets.QStyle.CE_CheckBox, checkbox_indicator, painter)
  19.  
  20.     def createEditor(self, parent, option, index):
  21.         """Editor for templates and tasks."""
  22.         index.model().setData(index, not index.data())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement