Changing Multiple Selection Mode for QListView

In QListView, I would like to disable the drag and drop of several elements with the mouse - that is, mous down the line, drag the mouse pointer and select the lines below it when dragging.

I would still like to select a row with a CTRL mouse click.

Is it possible?

+5
source share
2 answers

I think the easiest way to do this is to create a derived class from a QListView, and then override its mouseMoveEvent function. This function in the Qt code for QListView looks for the drag state and creates a rectangle. I think something like this might work, but I have not tested it:

void DerivedListView::mouseMoveEvent(QMouseEvent *e) {
    if (state() != DragSelectingState)
        QListView::mouseMoveEvent(e);
}
+3
source

, QAbstractItemView:: MultiSelection. QAbstractItemView:: ExtendedSelection :

listView->setSelectionMode( QAbstractItemView::ExtendedSelection );

, .

+7

All Articles