简体   繁体   中英

Multiple Selection table, without selection of mouse dragging

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.

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.

eg

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM