How do I get the items selected from a QTreeview?
-
I am trying to drag an item from the treeview to listview.
listview is promoted and thedropEventis shown below.
How can I get the dropped item from the row , col or mimedata ?void dropEvent(QDropEvent* event) { const QMimeData* mime = event->mimeData(); QByteArray encoded = mime->data("application/x-qabstractitemmodeldatalist"); QDataStream stream(&encoded, QIODevice::ReadOnly); while (!stream.atEnd()) { int row, col; QMap<int, QVariant> roleDataMap; stream >> row >> col >> roleDataMap; event->setDropAction(Qt::MoveAction); event->accept(); } } -
Hi,
You should take a look at the Using drag and drop with item views chapter of Qt's documentation.
It explains what you need to handle that.
-
Hi,
You should take a look at the Using drag and drop with item views chapter of Qt's documentation.
It explains what you need to handle that.
@SGaist
Thanks for the reply. Qt's documentation was helpful.
I was able to find the index of selected items in thedropEventusingQTreeView * view= dynamic_cast<QTreeView*>(event->source()); QModelIndexList list= view->selectionModel()->selectedIndexes();Is there any wayto do it in mimeData?
-
That's really not the role of mime data. What do you want to do with that information ?
-
Again passing object through mime data is not the right thing to do. But without knowing what you want to do with the indexes, it's pretty difficult to find a suitable solution.
-
Again passing object through mime data is not the right thing to do. But without knowing what you want to do with the indexes, it's pretty difficult to find a suitable solution.
-
What are the restriction rules ?