Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-103898

QListWidget::dropEvent processes already accepted events

    XMLWordPrintable

Details

    Description

      We have a widget, which inherits QListWidget and overrides its dropEvent method for custom drag & drop handling. In it we handle some of the proposed actions (i.e. modify the model and accept the action) and call the parent method (QListWidget::dropEvent) to finish the rest. In our case we've handled CopyAction, for example, and left MoveAction to the parent.

      This worked fine before in 5.12, as parent methods didn't modify the model, when the event was already accepted (there is a check in the dropOn method). But in 6.3 (and 5.15.3 for that matter) this no longer works for CopyAction because of the addition of this code at the end of QListView::dropEvent:

          if (!d->commonListView->filterDropEvent(event) || !d->dropEventMoved) {
              // icon view didn't move the data, and moveRows not implemented, so fall back to default
              if (!d->dropEventMoved)
                  event->ignore();
              QAbstractItemView::dropEvent(event);
          }

      So now, if QlistView didn't handle the event (and it handles only move events), it resets the "accepted" property, which causes QAbstractItemView::dropEvent further down the line to process the action on its own (i.e. create a copy).

      In summary it looks something like this:

      1. The custom dropEvent override handles the copy: makes all of the required changes to the model and accepts the event.
      2. Override in QListView doesn't handle the copy event, but makes the event ignored.
      3. In QAbstractItemView, since the event was ignored, we get another copy, so we get another copy besides (1).

      I've attached a small sample, which highlights the issue. If you copy an item (drag and drop with Ctrl), then the item appears twice, while it should be copied only once.

      Attachments

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            eswcvlad eswcvlad
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: