QListView icons movement
-
wrote on 28 Apr 2016, 10:22 last edited by A Former User 5 Sept 2016, 11:13
I would like to forbid movement of icons in the view but dragging to other views should stay enabled. Is there a way to achieve this?
-
Hi
setAcceptDrops(false);
might do it.
Else DragDropMode set to DragOnly -
wrote on 28 Apr 2016, 10:53 last edited by chabo
Hi,
sorry, I didn't mention it, but dropping to view should be enabled.
I have QListView attached to QFileSystemModel. I would like to drag&drop files from/to this view, but I I want to forbid moving of icons within the view only(changing their positions in view).possible solution could be: returns icon to its original position if it was dropped to the same view and it was not dropped to some element(I want overwrite file if it was dropped to other file or copy file to folder if it was dropped to folder)
-
Hi,
sorry, I didn't mention it, but dropping to view should be enabled.
I have QListView attached to QFileSystemModel. I would like to drag&drop files from/to this view, but I I want to forbid moving of icons within the view only(changing their positions in view).possible solution could be: returns icon to its original position if it was dropped to the same view and it was not dropped to some element(I want overwrite file if it was dropped to other file or copy file to folder if it was dropped to folder)
@chabo said:
If you have override then dropEvent/dropEnter
you can check for the source of the event.
if event->source() == this then reject
else accept
Yes same as your idea, but just forbid the actual drop so
no need moving it back. -
wrote on 28 Apr 2016, 13:56 last edited by
Thank you very much.
void MyListView::dropEvent(QDropEvent * event) { if (event->source() != this || indexAt(event->pos()).isValid()) { QListView::dropEvent(event); } }
1/5