Disable drag and drop for QListView
-
Hi!
I'm using a QListView to display some files.
I have set acceptDrops to false and all this stuff as well
but im still able to drag and drop the items. When setting defaultDropAction to ignoreAction, it will duplicate.Gates.
-
@TheGates
I recommend you to set it in your code as well not only in the designer.
Also, add some images to proper illustrate your issue. You can try to upload your image: https://imgbb.com/ and put the link here. -
Hello!
Have you tried to set
setDragDropMode
method toNoDragDrop
(https://doc.qt.io/qt-5/qabstractitemview.html#DragDropMode-enum)?
Also, I would recommend to block drops in theviewport()
as well:listView->viewport()->setAcceptDrops(false);
Happy coding! -
@Cobra91151 Ey, yes, the drag drop mode enum has been set to that, but It still does the same thing. (I thought I posted an image but it didn't work somehow)
I will try the viewport part right now.Edit because I cant post xD:
@TheGates said in Disable drag and drop for QListView:I will try the viewport part right now.
It is actually already set no not accepting drops at all in the designer! (which seems to be the default)
Is this maybe not a drag and drop action? -
@TheGates
I recommend you to set it in your code as well not only in the designer.
Also, add some images to proper illustrate your issue. You can try to upload your image: https://imgbb.com/ and put the link here. -
Yeah I tried uploading an image but I failed...
Anyways, Manually setting the DragDropMode worked... I don't know why the designer doesn't do this but okay.
Thanks for your help. -
@TheGates
Good. Sometimes designer has this issue. It is recommended to always set your properties in the code to make sure no such issue will occur in the future.
Anyway, you can mark this topic as solved. -
@TheGates , @Cobra91151
I don't know whether it's the same issue, but a while ago I fought for ages with a problem which, when I eventually figured it, turned out to be "strange/bad" behaviour with drag drop resulting from setting stuff on widgets in Designer, and had to be corrected in code. Make of it as you wish, here is the comment I left myself in code:// `countersListWidget` has had its `viewMode` set to `IconMode` in Designer // but then as per https://forum.qt.io/topic/131673/qlistwidget-drag-drop-documentation-behaviour/18 // this causes `setDragEnabled(true)` but *also* `setAcceptDrops(true)` // we do not want the icons to be draggable/re-arrangeable *within* the list widget // so we explicitly `setAcceptDrops(false)` here to disable that ui->countersListWidget->setAcceptDrops(false);
I see that I raised a whole thread at QListWidget drag/drop documentation/behaviour. It got complicated! :)