<s> from PyQt4 . QtCore import Qt <EOL> from PyQt4 . QtGui import QStyledItemDelegate , QStyle , QApplication <EOL> class CheckableItemDelegate ( QStyledItemDelegate ) : <EOL> """<STR_LIT>""" <EOL> CheckTypeRole = Qt . UserRole + <NUM_LIT> <EOL> CheckedRole = Qt . UserRole + <NUM_LIT> <EOL> CheckBoxCheckType = <NUM_LIT:1> <EOL> RadioCheckType = <NUM_LIT:2> <EOL> def __init__ ( self , viewWidget ) : <EOL> QStyledItemDelegate . __init__ ( self ) <EOL> self . viewWidget = viewWidget <EOL> self . counter = <NUM_LIT:0> <EOL> def paint ( self , painter , option , index ) : <EOL> style = QApplication . instance ( ) . style ( ) <EOL> if index . data ( CheckableItemDelegate . CheckTypeRole ) : <EOL> is_radio = index . data ( CheckableItemDelegate . CheckTypeRole ) == CheckableItemDelegate . RadioCheckType <EOL> if is_radio : <EOL> button_width = style . pixelMetric ( <EOL> QStyle . PM_ExclusiveIndicatorWidth , option ) <EOL> spacing = style . pixelMetric ( <EOL> QStyle . PM_RadioButtonLabelSpacing , option ) <EOL> else : <EOL> button_width = style . pixelMetric ( <EOL> QStyle . PM_IndicatorWidth , option ) <EOL> spacing = style . pixelMetric ( <EOL> QStyle . PM_CheckBoxLabelSpacing , option ) <EOL> myOption = option <EOL> left = myOption . rect . left ( ) <EOL> myOption . rect . setLeft ( left + spacing + button_width ) <EOL> QStyledItemDelegate . paint ( self , painter , myOption , index ) <EOL> myOption . rect . setLeft ( left ) <EOL> myOption . rect . setWidth ( button_width ) <EOL> if index . data ( CheckableItemDelegate . CheckedRole ) : <EOL> myOption . state |= QStyle . State_On <EOL> else : <EOL> myOption . state |= QStyle . State_Off <EOL> if is_radio : <EOL> style . drawPrimitive ( <EOL> QStyle . PE_IndicatorRadioButton , myOption , painter ) <EOL> else : <EOL> style . drawPrimitive ( <EOL> QStyle . PE_IndicatorCheckBox , myOption , painter ) <EOL> else : <EOL> QStyledItemDelegate . paint ( self , painter , option , index ) <EOL> def sizeHint ( self , option , index ) : <EOL> s = QStyledItemDelegate . sizeHint ( self , option , index ) <EOL> radio_height = QApplication . style ( ) . pixelMetric ( <EOL> QStyle . PM_ExclusiveIndicatorHeight , option ) <EOL> check_height = QApplication . style ( ) . pixelMetric ( <EOL> QStyle . PM_IndicatorHeight , option ) <EOL> s . setHeight ( max ( s . height ( ) , radio_height , check_height ) ) <EOL> return s </s>
