Starting Drag from QListWidget initiates Unwanted Selection

  • I have created the start of a drag action from a QListWidget. This QListWidget has selection mode ExtendedSelection, see also I would l like to keep this behavior except for the fact that it shouldn't do the selection behavior originating from drag events. How can I exclude selecting items by dragging with selection mode ExtendedSelection?

  • Lifetime Qt Champion


    What do you mean by you *you created the start of a grad action" ? Aren't you using the already implemented in Qt's item view classes ?

  • Here is the code for the QWidget where the QDrag starts

    void ClassList::mousePressEvent(QMouseEvent *Event) {
        if (Event->button() == Qt::LeftButton)
            DragStartPosition = Event->pos();
    void ClassList::mouseMoveEvent(QMouseEvent *Event) {
        if (Event->buttons() & Qt::LeftButton) {
            int Distance = (Event->pos() - DragStartPosition).manhattanLength();
            if (Distance >= QApplication::startDragDistance())
    void ClassList::performDrag() {
        if (currentItem())
            if (currentItem()->foreground() == Qt::black) {
                InstantiableItem *Current = static_cast<InstantiableItem *>(currentItem());
                InstantiableMime *Mime = new InstantiableMime(Current->item());
                QDrag *Drag = new QDrag(this);
                Drag->setPixmap(Current->icon().pixmap(QSize(20, 20)));

    InstantiableItem is my subclass of QListWidgetItem and InstantiableMine is my subclass of QMimeData. ClassList is a subclass of QListWidget.

  • Lifetime Qt Champion

    I'd recommend rather implementing your own list model based on the drag and drop model described here.

    That will likely make your implementation simpler and cleaner.

Log in to reply