After some investigation I found that the issue was that my editorEvent() method needed to return true (indicating that the cell contents have changed) to force the repaint of the cell and thus set the selected state. Code is below:
bool CheckBoxDelegate::editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index)
{
bool repaint_cell = false;
QMouseEvent *e = static_cast<QMouseEvent *> (event);
mouse_position_ = e->pos();
// We need to check if the mouse pointer is hovering within
// the checkbox indicator area of the table cell
QStyleOptionButton checkbox_indicator;
checkbox_indicator.rect = QApplication::style()->subElementRect( QStyle::SE_CheckBoxIndicator, &checkbox_indicator, NULL );
const int x = option.rect.center().x() - checkbox_indicator.rect.width() / 2;
const int y = option.rect.center().y() - checkbox_indicator.rect.height() / 2;
checkbox_indicator.rect.moveTo(x, y );
if (checkbox_indicator.rect.contains(mouse_position_)) {
repaint_cell = true;
// Check if the user has clicked in this area
if (e->button() == Qt::LeftButton) {
switch(event->type()) {
case QEvent::MouseButtonRelease:
// Update model data in here
break;
default:
break;
}
}
}
return repaint_cell;
}