Drag & Drop multiselection on QTableWidget
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!!
Re: Drag & Drop multiselection on QTableWidget
Set the internalMove property of the widget to false. Same for dragEnabled.
Re: Drag & Drop multiselection on QTableWidget
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(t blOutputs->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!
Re: Drag & Drop multiselection on QTableWidget
Ohhh.... you wanted to disable selection by dragging? I guess I misunderstood you then. In that case change selectionBehavior to something else than ExtendedSelection.
Re: Drag & Drop multiselection on QTableWidget
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!
Re: Drag & Drop multiselection on QTableWidget
QAbstractItemView::SelectionMode -- see the different selection modes and choose which fits you best.
Re: Drag & Drop multiselection on QTableWidget
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.
Re: Drag & Drop multiselection on QTableWidget
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.
Re: Drag & Drop multiselection on QTableWidget
Quote:
Originally Posted by
wysota
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!
Re: Drag & Drop multiselection on QTableWidget
Just make sure it doesn't ruin scrolling the widget by dragging the scroll bar.