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
Forum Updated to NodeBB v4.3 + New Features

Items after dropping from widget to widget missing

Scheduled Pinned Locked Moved Unsolved General and Desktop
qlistwidgetdrag and drop
6 Posts 2 Posters 981 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.
  • H Offline
    H Offline
    Huy Manh
    wrote on 11 May 2019, 11:38 last edited by Huy Manh 5 Nov 2019, 12:11
    #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
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 11 May 2019, 12:02 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
      • H Offline
        H Offline
        Huy Manh
        wrote on 11 May 2019, 12:09 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
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 11 May 2019, 12:19 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
          • H Offline
            H Offline
            Huy Manh
            wrote on 11 May 2019, 12:27 last edited by Huy Manh 5 Nov 2019, 12:28
            #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
            • C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 11 May 2019, 12:58 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

              6/6

              11 May 2019, 12:58

              • Login

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