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. Drag and Drop, MoveAction not deleting original position?
Qt 6.11 is out! See what's new in the release blog

Drag and Drop, MoveAction not deleting original position?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.2k 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.
  • M Offline
    M Offline
    maximus
    wrote on last edited by
    #1

    Hi,

    I have set 2 QListWidget that accept drag and drop,
    I'm moving one widget from list#1 to list#2, the item get copied but not moved, i'm trying to figure out why?
    Here is a screenshot of it :
    https://www.dropbox.com/s/ylm70suadtna9s3/DragDropInt.png

    Here is the current code :

    custom QListView

    @myQListWidget::myQListWidget(QWidget *parent) :QListWidget(parent)
    {
    setAcceptDrops(true);
    setDragDropMode(DragDrop);
    setDefaultDropAction(Qt::MoveAction);
    setDragEnabled(true);
    setDropIndicatorShown(true);
    }

    void myQListWidget::dragEnterEvent(QDragEnterEvent *event) {

    qDebug() << "dragEnterEvent";
    if (event->mimeData()->hasFormat("mt/interval") ) {
        qDebug() << "OK CAN ACCEPT DROP!";
        event->acceptProposedAction();
    }
    

    }
    void myQListWidget::dropEvent(QDropEvent *event) {

    qDebug() << "dropEvent";
    
    if (event->proposedAction() == Qt::MoveAction) {
    
        qDebug() << "EVENT SOURCE :" << event->source();
        /// Take QByteArray and create object from it
        //        const QMimeData *data = event->mimeData();
        //        QByteArray dataArray = data->data("mt/interval");
    
    
        QListWidgetItem* item;
        item = new QListWidgetItem(this);
        this->addItem(item);
    
        IntervalWidget *intervalWidget = new IntervalWidget();
        item->setSizeHint(intervalWidget->minimumSizeHint());
        this->setItemWidget(item, intervalWidget);
    
        event->acceptProposedAction();
    
        //        QListWidget::dropEvent(event);
    }
    

    }@

    Custom Widget

    @
    if (event->button() == Qt::LeftButton)
    dragStartPosition = event->pos();
    }

    void IntervalWidget::mouseMoveEvent(QMouseEvent *event) {

    if (!(event->buttons() & Qt::LeftButton))
        return;
    if ((event->pos() - dragStartPosition).manhattanLength()
            < QApplication::startDragDistance())
        return;
    
    QDrag *drag = new QDrag(this);
    QMimeData *mimeData = new QMimeData;
    
    QByteArray output;
    /// Write object to QByteArray
    mimeData->setData("mt/interval", output);
    drag->setMimeData(mimeData);
    

    // //// Image when moving the widget
    QPixmap pixmap(this->rect().size());
    this->render(&pixmap, QPoint(), QRegion(this->rect()));
    drag->setPixmap(pixmap);

    Qt::DropAction dropAction = drag->exec&#40;Qt::MoveAction&#41;;
    

    }@


    Free Indoor Cycling Software - https://maximumtrainer.com

    1 Reply Last reply
    0
    • M Offline
      M Offline
      maximus
      wrote on last edited by
      #2

      edited


      Free Indoor Cycling Software - https://maximumtrainer.com

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Did you look at "this":http://qt-project.org/doc/qt-5/model-view-programming.html#using-convenience-views about the model view classes and d&d ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        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