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. Items after dropping from widget to widget missing

Items after dropping from widget to widget missing

Scheduled Pinned Locked Moved Unsolved General and Desktop
qlistwidgetdrag and drop
6 Posts 2 Posters 1.5k Views
  • 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.
  • Huy ManhH Offline
    Huy ManhH Offline
    Huy Manh
    wrote on last edited by Huy Manh
    #1

    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.

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

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

      1 Reply Last reply
      0
      • Huy ManhH Offline
        Huy ManhH Offline
        Huy Manh
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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.

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

          1 Reply Last reply
          1
          • Huy ManhH Offline
            Huy ManhH Offline
            Huy Manh
            wrote on last edited by Huy Manh
            #5

            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.

            1 Reply Last reply
            0
            • Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

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

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

              1 Reply Last reply
              1

              • Login

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