Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Disable drag and drop for QListView
Forum Updated to NodeBB v4.3 + New Features

Disable drag and drop for QListView

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 1.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on 29 Apr 2022, 15:09 last edited by
    #1

    Hi!

    I'm using a QListView to display some files.
    I have set acceptDrops to false and all this stuff as well
    disabled dragEnabled NoDragDrop
    but im still able to drag and drop the items. When setting defaultDropAction to ignoreAction, it will duplicate.

    Gates.

    1 Reply Last reply
    0
    • ? A Former User
      29 Apr 2022, 18:47

      @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?

      C Offline
      C Offline
      Cobra91151
      wrote on 29 Apr 2022, 19:22 last edited by Cobra91151
      #4

      @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.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Cobra91151
        wrote on 29 Apr 2022, 16:58 last edited by
        #2

        Hello!

        Have you tried to set setDragDropMode method to NoDragDrop (https://doc.qt.io/qt-5/qabstractitemview.html#DragDropMode-enum)?
        Also, I would recommend to block drops in the viewport() as well: listView->viewport()->setAcceptDrops(false);
        Happy coding!

        ? 1 Reply Last reply 29 Apr 2022, 18:47
        2
        • C Cobra91151
          29 Apr 2022, 16:58

          Hello!

          Have you tried to set setDragDropMode method to NoDragDrop (https://doc.qt.io/qt-5/qabstractitemview.html#DragDropMode-enum)?
          Also, I would recommend to block drops in the viewport() as well: listView->viewport()->setAcceptDrops(false);
          Happy coding!

          ? Offline
          ? Offline
          A Former User
          wrote on 29 Apr 2022, 18:47 last edited by A Former User
          #3

          @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?

          C 1 Reply Last reply 29 Apr 2022, 19:22
          0
          • ? A Former User
            29 Apr 2022, 18:47

            @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?

            C Offline
            C Offline
            Cobra91151
            wrote on 29 Apr 2022, 19:22 last edited by Cobra91151
            #4

            @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.

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on 29 Apr 2022, 20:00 last edited by
              #5

              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.

              C 1 Reply Last reply 29 Apr 2022, 20:10
              0
              • ? A Former User
                29 Apr 2022, 20:00

                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.

                C Offline
                C Offline
                Cobra91151
                wrote on 29 Apr 2022, 20:10 last edited by Cobra91151
                #6

                @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.

                1 Reply Last reply
                0
                • J Online
                  J Online
                  JonB
                  wrote on 30 Apr 2022, 07:32 last edited by JonB
                  #7

                  @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! :)

                  1 Reply Last reply
                  0

                  2/7

                  29 Apr 2022, 16:58

                  topic:navigator.unread, 5
                  • Login

                  • Login or register to search.
                  2 out of 7
                  • First post
                    2/7
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved