QAbstractItemView updates the selection in mouse event handlers. You will have to override at least mousePressEvent() and prevent QAbstractItemView from handling the event if mouse was pressed over the checkbox. You will most propably have to add some checks in mouseReleaseEvent() too, otherwise the selection behaviour might get broken.
Here's the code for detecting if a mouse event occurs over item's checkbox:
if (idx.isValid())
{
opt.rect = visualRect(idx);
QRect rect
= style
()->subElementRect
(QStyle::SE_ViewItemCheckIndicator,
&opt
);
if (rect.contains(event->pos()))
{
// pressed/released over the checkbox...
}
}
QModelIndex idx = indexAt(event->pos());
if (idx.isValid())
{
QStyleOptionButton opt;
opt.QStyleOption::operator=(viewOptions());
opt.rect = visualRect(idx);
QRect rect = style()->subElementRect(QStyle::SE_ViewItemCheckIndicator, &opt);
if (rect.contains(event->pos()))
{
// pressed/released over the checkbox...
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks