I managed to get by with the paint() method, but I'm kinda stuck with editorEvent(). Edit: I had a look at QItemDelegate source and found how to do it:
{
Q_UNUSED(option);
if (event
->type
() == QEvent::MouseButtonRelease) { QVariant value
= index.
data(Qt
::CheckStateRole);
Qt::CheckState state = (static_cast<Qt::CheckState>(value.toInt()) == Qt::Checked
? Qt::Unchecked : Qt::Checked);
return model->setData(index, state, Qt::CheckStateRole);
} else
return false;
}
bool CheckableItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
{
Q_UNUSED(option);
if (event->type() == QEvent::MouseButtonRelease) {
QVariant value = index.data(Qt::CheckStateRole);
Qt::CheckState state = (static_cast<Qt::CheckState>(value.toInt()) == Qt::Checked
? Qt::Unchecked : Qt::Checked);
return model->setData(index, state, Qt::CheckStateRole);
} else
return false;
}
To copy to clipboard, switch view to plain text mode
This will intercept all mouse clicks on the item (and I'm ok with it).
Bookmarks