def _getCheckboxRect(self, boundingRect): """ Get the bounding box of a checkbox that has been centered in a cell :rtype: QtCore.QRect """ checkboxRect = QtGui.QApplication.style().subElementRect( QtGui.QStyle.SE_CheckBoxIndicator, QtGui.QStyleOptionButton(), None) checkboxRect.moveCenter(boundingRect.center()) return checkboxRect
def _paintBoolean(self, painter, option, index): """ Draw a check box :parameters: painter : QtGui.QPainter painter to draw the image with option : QtGui.QStyleOption style information index : QtCore.QModelIndex index if the cell to draw """ buttonStyleOption = QtGui.QStyleOptionButton() # set the check state based on the boolean value for this model index buttonStyleOption.state = QtGui.QStyle.State_On if index.data( ) else QtGui.QStyle.State_Off # center the checkbox in the cell buttonStyleOption.rect = self._getCheckboxRect(option.rect) # paint the checkbox painter.save() QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_CheckBox, buttonStyleOption, painter) painter.restore()