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

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

      Cobra91151C Offline
      Cobra91151C Offline
      Cobra91151
      wrote on 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
      • Cobra91151C Offline
        Cobra91151C Offline
        Cobra91151
        wrote on 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
        2
        • Cobra91151C Cobra91151

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

          Cobra91151C 1 Reply Last reply
          0
          • ? A Former User

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

            Cobra91151C Offline
            Cobra91151C Offline
            Cobra91151
            wrote on 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 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.

              Cobra91151C 1 Reply Last reply
              0
              • ? A Former User

                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.

                Cobra91151C Offline
                Cobra91151C Offline
                Cobra91151
                wrote on 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
                • JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on 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

                  • Login

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