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