PDA

View Full Version : Drag & Drop multiselection on QTableWidget



jbarrena
24th November 2014, 14:04
Hi all!!

I am developing an application with some qtablewidgets that are multi selection enabled. The point is that I need to avoid the drag & drop multiselection property from the tables. Is there any possibility to set this property to false for the QTableWidget?

Thanks in advance!!

wysota
25th November 2014, 07:53
Set the internalMove property of the widget to false. Same for dragEnabled.

jbarrena
25th November 2014, 09:15
Thanks for the reply wysota!

I added these two sentences to the code but nothing change in the qtablewidget behavior:

tblOutputs->setDragEnabled(false);
tblOutputs->setDragDropMode(QAbstractItemView::DragDropMode(tb lOutputs->dragDropMode() & ~QAbstractItemView::InternalMove));

In fact, tblOutputs->dragDropMode() returns 0, so it seems that drag and drop is disabled, but it selects multiple rows dragging the mouse from the table while clicking left button. I do not know what´s the problem...

Thanks!

wysota
25th November 2014, 09:24
Ohhh.... you wanted to disable selection by dragging? I guess I misunderstood you then. In that case change selectionBehavior to something else than ExtendedSelection.

jbarrena
25th November 2014, 09:39
No, but I need to select multiple rows by clicking on items, but I do not need to select rows by dragging the mouse. I need to disable this behavior, but still continue selecting multiple rows by only clicking on items.

Any idea??

Thanks again!

wysota
25th November 2014, 10:10
QAbstractItemView::SelectionMode -- see the different selection modes and choose which fits you best.

jbarrena
25th November 2014, 11:20
The problem is that both of the multiple-selection-options tips "Multiple items can be toggled by dragging the mouse over them". And what I don´t want to happen is exactly that behaviour, to select rows by dragging mouse.

wysota
25th November 2014, 12:56
Then your only option is to prevent the view for getting and drag-like events at all by applying an event filter on the view's viewport and filtering out MouseMove events. Alternatively you can probably set the view to NoSelection mode and implement selection yourself the way you like it.

jbarrena
27th November 2014, 16:14
Then your only option is to prevent the view for getting and drag-like events at all by applying an event filter on the view's viewport and filtering out MouseMove events. Alternatively you can probably set the view to NoSelection mode and implement selection yourself the way you like it.

Thanks!

I created a class inherited from QTableWidget and overwrite mouseMoveEvent. Thanks for your support!

wysota
27th November 2014, 17:15
Just make sure it doesn't ruin scrolling the widget by dragging the scroll bar.