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. QListWidget drag/drop documentation/behaviour
Forum Updated to NodeBB v4.3 + New Features

QListWidget drag/drop documentation/behaviour

Scheduled Pinned Locked Moved Unsolved General and Desktop
25 Posts 3 Posters 4.9k Views 2 Watching
  • 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.
  • Pl45m4P Pl45m4

    @JonB said in QListWidget drag/drop documentation/behaviour:

    I invite you to place the following line above your two lines:

    The only thing how I could explain it, is that as I've assumed before, the different "modes" are handled independently.
    Default mode is not IconMode. So maybe all the settings you make, only apply for the current mode (intentionally or not?!) and when you switch the viewMode everything resets / defaults, so you can drop the stuff again... oof... :)

    QtDesigner at it's best :P

    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by
    #21

    @Pl45m4
    As I showed in the code from your woboq file, it's kind of like that, but not completely. Setting IconMode causes a couple of changes to be made. The trouble is, where they put that line in the ui....h file from Designer properties "undoes" some of the other proprieties you have also set there. Without you realising.

    Anyway, I'm good to go now that I know why & what, just "bruised" from the length of the tussle... ;-)

    Pl45m4P 1 Reply Last reply
    1
    • JonBJ JonB

      @Pl45m4
      As I showed in the code from your woboq file, it's kind of like that, but not completely. Setting IconMode causes a couple of changes to be made. The trouble is, where they put that line in the ui....h file from Designer properties "undoes" some of the other proprieties you have also set there. Without you realising.

      Anyway, I'm good to go now that I know why & what, just "bruised" from the length of the tussle... ;-)

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #22

      @JonB said in QListWidget drag/drop documentation/behaviour:

      The trouble is, where they put that line in the ui....h file from Designer properties "undoes" some of the other proprieties you have also set there.

      Yes... so it's impossible to get that behavior you asked for, when using QtDesigner even tho it is theoretically possible because these are just 3 properties. Just a matter of order. If uic will always put it this way... it doesn't work and you don't know why :)

      Another reason to use QtD for placing widgets and other stuff only and do the rest with code :)


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      1
      • JonBJ JonB

        @VRonin said in QListWidget drag/drop documentation/behaviour:

            listWid->setDragEnabled(true);
            listWid->setDragDropMode(QAbstractItemView::DragOnly);
        

        Dear @VRonin,

        I hope you might take a couple of minutes to look at this --- just OOI and to feel my pain --- since I have spent so much time trying to figure why your sample code does work but that generated from Designer does not.

        I invite you to place the following line above your two lines:

         listWid->setViewMode(QListView::IconMode);
        

        (The only thing I care about is that you can still start a drag, and you cannot drop the drag back in the list widget to cause changed layout.) Everything still works, right?

        Now please move that line to after the original two lines. This is where it ends up from the .ui file/uic generator to ui_....h from setting all these properties. Now try.... You can now drag & drop the items around the list widget to re-arrange them, can't you? Which is what I was wanting to prevent.

        Now that I have figured this I am of course OK going forward. But I should like sympathy for how long it has taken to me to determine what has been going on... ;-)

        VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #23

        @JonB said in QListWidget drag/drop documentation/behaviour:

        Now please move that line to after the original two lines. This is where it ends up from the .ui file/uic generator to ui_....h from setting all these properties. Now try.... You can now drag & drop the items around the list widget to re-arrange them, can't you? Which is what I was wanting to prevent.

        Indeed, this is due to QListView::setViewMode overwriting the acceptDrops property (see https://code.woboq.org/qt5/qtbase/src/widgets/itemviews/qlistview.cpp.html#_ZN9QListView11setViewModeENS_8ViewModeE). It's been like this since before the Nokia days so I can't easily dig out why this is the case.

        For people ending up here from a search engine, the solution is to put ui->listWidget->setDragDropMode(QAbstractItemView::DragOnly); in your widget constructor after the call to setupUi()

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        JonBJ 1 Reply Last reply
        2
        • VRoninV VRonin

          @JonB said in QListWidget drag/drop documentation/behaviour:

          Now please move that line to after the original two lines. This is where it ends up from the .ui file/uic generator to ui_....h from setting all these properties. Now try.... You can now drag & drop the items around the list widget to re-arrange them, can't you? Which is what I was wanting to prevent.

          Indeed, this is due to QListView::setViewMode overwriting the acceptDrops property (see https://code.woboq.org/qt5/qtbase/src/widgets/itemviews/qlistview.cpp.html#_ZN9QListView11setViewModeENS_8ViewModeE). It's been like this since before the Nokia days so I can't easily dig out why this is the case.

          For people ending up here from a search engine, the solution is to put ui->listWidget->setDragDropMode(QAbstractItemView::DragOnly); in your widget constructor after the call to setupUi()

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #24

          @VRonin
          Thank you for this. You may be able to see why I was so confused!

          I would also say that as per my comment earlier I actually put in the following (after setupUi()) to address the issue:

          ui->listWidget->setAcceptDrops(false);
          

          I don't know how that compares against your ui->listWidget->setDragDropMode(QAbstractItemView::DragOnly), I can only say it is what is working for me in the situation I described.

          VRoninV 1 Reply Last reply
          1
          • JonBJ JonB

            @VRonin
            Thank you for this. You may be able to see why I was so confused!

            I would also say that as per my comment earlier I actually put in the following (after setupUi()) to address the issue:

            ui->listWidget->setAcceptDrops(false);
            

            I don't know how that compares against your ui->listWidget->setDragDropMode(QAbstractItemView::DragOnly), I can only say it is what is working for me in the situation I described.

            VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #25

            @JonB said in QListWidget drag/drop documentation/behaviour:

            I don't know how that compares against your ui->listWidget->setDragDropMode(QAbstractItemView::DragOnly)

            setDragDropMode calls setAcceptDrops so either works

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply
            1

            • Login

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