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

QListWidget drag&drop

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 4.7k 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.
  • S Offline
    S Offline
    Sibyx
    wrote on last edited by
    #1

    Hi,
    i have 3 instances of object based on QListWidget (on picture boxes with gray borders). In one of this widgets are items with icons and a need move this items to other widgets, without copying. How to? Thanks!
    !http://mksoft.marconet.sk/pics/SOC-forum.jpg(Preview)!

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tucnak
      wrote on last edited by
      #2

      New Year on the street! Wait with dev. It is whole 2012 year in front of you!

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Sibyx
        wrote on last edited by
        #3

        I'm from Slovakia and I had new year 14 hours earlier, and I need finish this project before end of January. I have a lot of work :)

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Sibyx
          wrote on last edited by
          #4

          I'm also tried this:
          @
          void ListBox::startDrag(Qt::DropActions supportedActions)
          {
          QListWidget::startDrag(supportedActions);
          delete this->currentItem();
          }
          @
          Now it works, but it has one problem, if is drop unsuccessfull, item is deleted too. I don't know how to solve this. How I can access to data of dragged QListWidgetItem?

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Sibyx
            wrote on last edited by
            #5

            I solved this, here is my code:
            @
            void ListBox::dragMoveEvent(QDragMoveEvent *e)
            {
            if (e->mimeData()->hasFormat("application/x-item") && e->source() != this) {
            e->setDropAction(Qt::MoveAction);
            e->accept();
            } else
            e->ignore();
            }

            void ListBox::dropEvent(QDropEvent *event)
            {
            if (event->mimeData()->hasFormat("application/x-item")) {
            event->accept();
            event->setDropAction(Qt::MoveAction);
            QListWidgetItem *item = new QListWidgetItem;
            QString name = event->mimeData()->data("application/x-item");
            item->setText(name);
            /if (provider->getColumnType(name) == "text") {
            item->setIcon(QIcon(":/images/iString"));
            }
            else {
            item->setIcon(QIcon(":/images/iInteger"));
            }
            /
            addItem(item);
            } else
            event->ignore();
            }

            void ListBox::startDrag(Qt::DropActions supportedActions)
            {
            QListWidgetItem *item = currentItem();
            QMimeData *mimeData = new QMimeData;
            QByteArray ba;
            ba = item->text().toLatin1().data();
            mimeData->setData("application/x-item", ba);
            QDrag *drag = new QDrag(this);
            drag->setMimeData(mimeData);
            if (drag->exec(Qt::MoveAction) == Qt::MoveAction)
            delete takeItem(row(item));
            }

            void ListBox::dragEnterEvent(QDragEnterEvent *event)
            {
            if (event->mimeData()->hasFormat("application/x-item"))
            event->accept();
            else
            event->ignore();
            }

            Qt::DropAction ListBox::supportedDropActions()
            {
            return Qt::MoveAction;
            }
            @

            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