I just got it done, hope this will work in general case
void TestDelegate
::paint(QPainter *painter,
{
if (index.column() == 1)
{
bool data = index.model()->data(index, Qt::DisplayRole).toBool();
checkboxstyle.rect = option.rect;
checkboxstyle.rect.setLeft(option.rect.x() +
option.rect.width()/2 - checkbox_rect.width()/2);
if(data)
checkboxstyle.
state = QStyle::State_On|QStyle
::State_Enabled;
else
checkboxstyle.
state = QStyle::State_Off|QStyle
::State_Enabled;
}
else
{
QStyledItemDelegate::paint(painter, option, index);
}
}
void TestDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
if (index.column() == 1)
{
bool data = index.model()->data(index, Qt::DisplayRole).toBool();
QStyleOptionButton checkboxstyle;
QRect checkbox_rect = QApplication::style()->subElementRect(QStyle::SE_CheckBoxIndicator, &checkboxstyle);
checkboxstyle.rect = option.rect;
checkboxstyle.rect.setLeft(option.rect.x() +
option.rect.width()/2 - checkbox_rect.width()/2);
if(data)
checkboxstyle.state = QStyle::State_On|QStyle::State_Enabled;
else
checkboxstyle.state = QStyle::State_Off|QStyle::State_Enabled;
QApplication::style()->drawControl(QStyle::CE_CheckBox, &checkboxstyle, painter);
}
else
{
QStyledItemDelegate::paint(painter, option, index);
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks