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 from a QListWidget, drop to QGraphicsScene (custom child class).

Drag from a QListWidget, drop to QGraphicsScene (custom child class).

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 897 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.
  • R Offline
    R Offline
    Rhadel
    wrote on last edited by
    #1

    Hi,

    I'm trying to drag and drop from a QListWidget to a QGraphicsScene child class. In order to that, I ve created a QListWidget subclass that implements:

    @
    void dropEvent(QGraphicsSceneDragDropEvent*);
    void dragEnterEvent(QGraphicsSceneDragDropEvent*);
    void dragMoveEvent(QGraphicsSceneDragDropEvent*);
    void mousePressEvent(QMouseEvent*);
    @

    When I create items for QListWidget, I do it as follow:

    @
    foreach (QString current, ViewItem::getAvailableItems()){ //Available items is a static list of strings.
    QListWidgetItem* item = new QListWidgetItem;
    QByteArray dataIn;
    QDataStream dataStream (&dataIn, QIODevice::WriteOnly);
    dataStream << current;
    QMimeData* mimeData = new QMimeData;
    mimeData->setData("datatext", dataStream);

        /////QDrag* drag = new QDrag(ui->availableItemsList); //Unused
        /////drag->setMimeData(mimeData);
    
        item->setData(1001, QString(current));
        ui->availableItemsList->addItem(item);
        qDebug() << "Data: " << current;
    }
    

    @

    In order to recieve the items, at QGraphicsScene subclass I have implemented:

    @
    void CustomScene::dropEvent(QGraphicsSceneDragDropEvent* event)
    {
    const QMimeData* data = event->mimeData();
    if (data->hasText()){
    QByteArray info = data->data("datatext");
    QString infostr (info);
    qDebug() << "Information: " << infostr;
    }

    }
    @

    qDebug () shows an empty string (""). How can I pass data from the List to de Scene?

    Thank you.

    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