Multiple Selection table, without selection of mouse dragging

1k views Asked by At

I would like to have QAbstractItemView that will allow multi-selection of items only with ctrl button toggle. I can't use QAbstractItemView::ExtandedSelection because it also allow multiple items selection by dragging the mouse over them.

1

There are 1 answers

0
PRIME On

I assume you are using a QTableView You can override the QTableView and then use mouseMoveEvent cleverly to ensure that user can't make multiple selections by dragging!

If user enters into mouseMoveEvent with the left mouse button pressed, you can choose to eat the event without passing it to the QTableView that will remove the possibility of multiple selection.

e.g.

void
TableView::mouseMoveEvent( QMouseEvent * inEvent )
{
// Deliberately commented to not to pass this event to parent to avoid multiple selection
// QTableView( inEvent );
inEvent->accept();
}

This might work for you, you may also have to be careful in the mouseMoveEvent, when you do above to mousePressEvent you have to do the same for mouseReleaseEvent as well.

Though this is just a theory , but is should work!