Items after dropping from widget to widget missing



  • After dragging and dropping an item from a list widget to a list widget, the item disappears in the target list widget.

    I used eventFilter for only the list widgets in MainWindow.

    bool MainWindow::eventFilter(QObject *target,QEvent *event){
        if (event->type() == QEvent::DragEnter)
           {
              QDragEnterEvent *tDragEnterEvent = static_cast<QDragEnterEvent *>(event);
              tDragEnterEvent->acceptProposedAction();
    
              return true;
           }
           else if (event->type() == QEvent::DragMove)
           {
              QDragMoveEvent *tDragMoveEvent = static_cast<QDragMoveEvent *>(event);
              tDragMoveEvent->acceptProposedAction();
    
              return true;
           }
            else if (event->type() == QEvent::Drop)
           {
              QDropEvent *tDropEvent = static_cast<QDropEvent *>(event);
              tDropEvent->acceptProposedAction();
    
              qDebug() << "OK, execute your task!";
    
              return true;
           }
           else
           {
               // standard event processing
               return QObject::eventFilter(target, event);
           }
    
    
        //return false;
    }
    //in MainWindow constructor
    ui->listWidget->installEventFilter(this);
    

    qDebug showed the debug string after dropping but the item went missing.


  • Qt Champions 2018

    You filter out the drop events and the wonder why the widget which should receive them don't receive them? Mhh.



  • Sorry but I don't know your meaning, I've been using Qt for about 3 months and this is the first time I handle events, so I hope you can help me with this minor problem, thank you.


  • Qt Champions 2018

    See documentation for QObject::eventFilter(): "... if you want to filter the event out, i.e. stop it being handled further, return true; ..." which is exactly what you're doing.



  • Oh, I get it. Can you suggest for me a solution? That is, if I drop an item into the list widget, I have a variable "count" plus 1 and if I drag an item out, "count" minus 1. I thought at first that eventFilter will help me.


  • Qt Champions 2018

    Drag'n'Drop from a QListWidget to another QListWidget should work out-of-the-box if dragEnabled/acceptDrops is active - see documentation


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.