I just got it done, hope this will work in general case
Qt Code:
  1. void TestDelegate::paint(QPainter *painter,
  2. const QStyleOptionViewItem &option,
  3. const QModelIndex &index) const
  4. {
  5. if (index.column() == 1)
  6. {
  7. bool data = index.model()->data(index, Qt::DisplayRole).toBool();
  8. QStyleOptionButton checkboxstyle;
  9. QRect checkbox_rect = QApplication::style()->subElementRect(QStyle::SE_CheckBoxIndicator, &checkboxstyle);
  10. checkboxstyle.rect = option.rect;
  11. checkboxstyle.rect.setLeft(option.rect.x() +
  12. option.rect.width()/2 - checkbox_rect.width()/2);
  13. if(data)
  14. checkboxstyle.state = QStyle::State_On|QStyle::State_Enabled;
  15. else
  16. checkboxstyle.state = QStyle::State_Off|QStyle::State_Enabled;
  17.  
  18. QApplication::style()->drawControl(QStyle::CE_CheckBox, &checkboxstyle, painter);
  19. }
  20. else
  21. {
  22. QStyledItemDelegate::paint(painter, option, index);
  23. }
  24. }
To copy to clipboard, switch view to plain text mode