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

QListWidget drag&drop item disappear

Scheduled Pinned Locked Moved Unsolved General and Desktop
17 Posts 4 Posters 3.5k Views 1 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.
  • P Paddle

    I work on a very large project so I'm actually not sure how to provide a basic example.

    However in this description of the problem : https://stackoverflow.com/questions/74263946/widget-inside-qlistwidgetitem-disappears-after-internal-move

    And this one : https://stackoverflow.com/questions/72529707/qlistwidget-items-dissapear-when-drag-dropped

    It appears that you just need a 'QListWidget' which is populated by QLabel or QCheckbox via .setItemWidget() and a drag and drop mode InternalMove.

    Then you should have this behavior, widget disappearing.

    Christian EhrlicherC Offline
    Christian EhrlicherC Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by
    #8

    I won't write a proper testcase for you. My testcase is working so there is no bug until I see it in a minimal, compilable example.

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    Axel SpoerlA 1 Reply Last reply
    0
    • Christian EhrlicherC Christian Ehrlicher

      I won't write a proper testcase for you. My testcase is working so there is no bug until I see it in a minimal, compilable example.

      Axel SpoerlA Offline
      Axel SpoerlA Offline
      Axel Spoerl
      Moderators
      wrote on last edited by Axel Spoerl
      #9

      @Christian-Ehrlicher
      Oh, that's a complicated case, see https://bugreports.qt.io/browse/QTBUG-100128.
      In a nut shell: When a QListWidgetItemis dragged and dropped, the information about it is rightfully stored in mime data and the item is reconstructed from that data at its new position. That works fine, as long as we're talking about a QListWidgetItem.

      In that particular case, an item widget takes it over: It carries the information to be displayed on the screen and the list widget item becomes just a container.

      When the drag and drop happens, it's not supported to serialize all information about an arbitrary widget into mime data and reconstruct it upon drop. That case can only be solved on application level. The data necessary to reconstruct an item widget could for instance be stored in a QVariant on list widget item level. The drop event would need to be intercepted and the item widget reconstructed.

      It's not a bug.

      Software Engineer
      The Qt Company, Oslo

      JonBJ 1 Reply Last reply
      0
      • Axel SpoerlA Axel Spoerl

        @Christian-Ehrlicher
        Oh, that's a complicated case, see https://bugreports.qt.io/browse/QTBUG-100128.
        In a nut shell: When a QListWidgetItemis dragged and dropped, the information about it is rightfully stored in mime data and the item is reconstructed from that data at its new position. That works fine, as long as we're talking about a QListWidgetItem.

        In that particular case, an item widget takes it over: It carries the information to be displayed on the screen and the list widget item becomes just a container.

        When the drag and drop happens, it's not supported to serialize all information about an arbitrary widget into mime data and reconstruct it upon drop. That case can only be solved on application level. The data necessary to reconstruct an item widget could for instance be stored in a QVariant on list widget item level. The drop event would need to be intercepted and the item widget reconstructed.

        It's not a bug.

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

        @Axel-Spoerl
        Hi Axel. I'm afraid I don't think your explanation is right. Remember the issue is about a particular item, along the lines of the last one and where you drop it to. I don't think "mime data" is relevant here.

        Have a look again at https://bugreports.qt.io/browse/QTBUG-100128. I think someone else may have posted there subsequent to your post.

        Axel SpoerlA 1 Reply Last reply
        0
        • JonBJ JonB

          @Axel-Spoerl
          Hi Axel. I'm afraid I don't think your explanation is right. Remember the issue is about a particular item, along the lines of the last one and where you drop it to. I don't think "mime data" is relevant here.

          Have a look again at https://bugreports.qt.io/browse/QTBUG-100128. I think someone else may have posted there subsequent to your post.

          Axel SpoerlA Offline
          Axel SpoerlA Offline
          Axel Spoerl
          Moderators
          wrote on last edited by
          #11

          @JonB
          Well, thanks for the reminder, Jon. I will look into that again.
          In my tests, the item was prepared to be dragged away, e.g. to another list widget. Loss of widget item is unavoidable in that case.

          Software Engineer
          The Qt Company, Oslo

          JonBJ 1 Reply Last reply
          0
          • Axel SpoerlA Axel Spoerl

            @JonB
            Well, thanks for the reminder, Jon. I will look into that again.
            In my tests, the item was prepared to be dragged away, e.g. to another list widget. Loss of widget item is unavoidable in that case.

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

            @Axel-Spoerl
            The OP here wrote in first post:

            It works but there's a bug : if I drop an item just below itself, then it disappear. Dropping just above works correctly. So it feels like when it's trying to replace itself, in one direction it looses the widget by doing so.

            This is an (attempted) drag-drop to move one list item within the QListWidget it is already in to a different index within that list widget. For that there should be no serialization/deserialization. It appears there is a specific case --- I think to do with being or being dragged to the last item --- which goes wrong. The "fix" @Paddle has posted into https://bugreports.qt.io/browse/QTBUG-100128 for his QListWidgetDragBugFix introduces a special case to ignore where

                if ((row(itemAt(e->pos())) == currentRow() + 1) 
                    || (currentRow() == count() - 1 && row(itemAt(e->pos())) == -1))
            

            so it's to handle a very specific case.

            Axel SpoerlA 1 Reply Last reply
            0
            • JonBJ JonB

              @Axel-Spoerl
              The OP here wrote in first post:

              It works but there's a bug : if I drop an item just below itself, then it disappear. Dropping just above works correctly. So it feels like when it's trying to replace itself, in one direction it looses the widget by doing so.

              This is an (attempted) drag-drop to move one list item within the QListWidget it is already in to a different index within that list widget. For that there should be no serialization/deserialization. It appears there is a specific case --- I think to do with being or being dragged to the last item --- which goes wrong. The "fix" @Paddle has posted into https://bugreports.qt.io/browse/QTBUG-100128 for his QListWidgetDragBugFix introduces a special case to ignore where

                  if ((row(itemAt(e->pos())) == currentRow() + 1) 
                      || (currentRow() == count() - 1 && row(itemAt(e->pos())) == -1))
              

              so it's to handle a very specific case.

              Axel SpoerlA Offline
              Axel SpoerlA Offline
              Axel Spoerl
              Moderators
              wrote on last edited by
              #13

              So, it appears that my judgement was wrong. Thanks, @JonB for pointing it out.
              I suggest to close this thread and follow the case up in https://bugreports.qt.io/browse/QTBUG-100128.
              I'll reopen it. Please check there if the latest reproducer reproduces the problem correctly.
              Over and out.

              Software Engineer
              The Qt Company, Oslo

              Christian EhrlicherC 1 Reply Last reply
              1
              • Axel SpoerlA Axel Spoerl

                So, it appears that my judgement was wrong. Thanks, @JonB for pointing it out.
                I suggest to close this thread and follow the case up in https://bugreports.qt.io/browse/QTBUG-100128.
                I'll reopen it. Please check there if the latest reproducer reproduces the problem correctly.
                Over and out.

                Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #14

                Fixed in Qt6.6

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                Axel SpoerlA 1 Reply Last reply
                2
                • Christian EhrlicherC Christian Ehrlicher

                  Fixed in Qt6.6

                  Axel SpoerlA Offline
                  Axel SpoerlA Offline
                  Axel Spoerl
                  Moderators
                  wrote on last edited by
                  #15

                  @Christian-Ehrlicher ...and 6.5 and 6.2.

                  Software Engineer
                  The Qt Company, Oslo

                  Christian EhrlicherC 1 Reply Last reply
                  0
                  • Axel SpoerlA Axel Spoerl

                    @Christian-Ehrlicher ...and 6.5 and 6.2.

                    Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #16

                    @Axel-Spoerl Correct, but imo we should put it into 5.15 too but it's commercial only so no actions from my side possible.

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    Axel SpoerlA 1 Reply Last reply
                    0
                    • Christian EhrlicherC Christian Ehrlicher

                      @Axel-Spoerl Correct, but imo we should put it into 5.15 too but it's commercial only so no actions from my side possible.

                      Axel SpoerlA Offline
                      Axel SpoerlA Offline
                      Axel Spoerl
                      Moderators
                      wrote on last edited by
                      #17

                      @Christian-Ehrlicher I've alrady cherry-picked it there, but integration fails with unrelated errors. Need to investigate...after the weekend.

                      Software Engineer
                      The Qt Company, Oslo

                      1 Reply Last reply
                      0
                      • JonBJ JonB referenced this topic on

                      • Login

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