How to get item after drag item from QListWidget Thumbnails
-
And do you want to know it as soon as the item is dragged or when it gets dropped somewhere else?
-
then you need to reimplement
void startDrag(Qt::DropActions supportedActions)
with:void startDrag(Qt::DropActions supportedActions){ QTableWidget::startDrag(supportedActions); QModelIndexList indexes = selectionModel()->selectedIndexes(); auto isNotDragEnabled = [this](const QModelIndex &index) { return !(model()->flags(index) & Qt::ItemIsDragEnabled); }; indexes.erase(std::remove_if(indexes.begin(), indexes.end(), isNotDragEnabled), indexes.end()); QVector<QListWidgetItem*> draggetItems; draggetItems.reserve(indexes.size()); for(auto& index : qAsConst(indexes)) draggetItems << itemAt(index.row())); // now draggetItems contains the list of dragged items
-
then you need to reimplement
void startDrag(Qt::DropActions supportedActions)
with:void startDrag(Qt::DropActions supportedActions){ QTableWidget::startDrag(supportedActions); QModelIndexList indexes = selectionModel()->selectedIndexes(); auto isNotDragEnabled = [this](const QModelIndex &index) { return !(model()->flags(index) & Qt::ItemIsDragEnabled); }; indexes.erase(std::remove_if(indexes.begin(), indexes.end(), isNotDragEnabled), indexes.end()); QVector<QListWidgetItem*> draggetItems; draggetItems.reserve(indexes.size()); for(auto& index : qAsConst(indexes)) draggetItems << itemAt(index.row())); // now draggetItems contains the list of dragged items
@VRonin said in How to get item after drag item from QListWidget Thumbnails:
QModelIndexList indexes = selectedIndexes();
Its showing selectIndex() is undefined.
I m added this one code for startDrag:-
void GLWidgetdrag::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)); emit itemDroped();*/ } }
Still Here showing this one error " QListWidgetItem* item = currentItem(); "
-
Its showing selectIndex() is undefined.
yes, sorry, I forgot 1 call, it's
selectionModel()->selectedIndexes()
, corrected now. I have no idea what you are trying to do in your implementation -
then you need to reimplement
void startDrag(Qt::DropActions supportedActions)
with:void startDrag(Qt::DropActions supportedActions){ QTableWidget::startDrag(supportedActions); QModelIndexList indexes = selectionModel()->selectedIndexes(); auto isNotDragEnabled = [this](const QModelIndex &index) { return !(model()->flags(index) & Qt::ItemIsDragEnabled); }; indexes.erase(std::remove_if(indexes.begin(), indexes.end(), isNotDragEnabled), indexes.end()); QVector<QListWidgetItem*> draggetItems; draggetItems.reserve(indexes.size()); for(auto& index : qAsConst(indexes)) draggetItems << itemAt(index.row())); // now draggetItems contains the list of dragged items
-
@VRonin said in How to get item after drag item from QListWidget Thumbnails:
auto isNotDragEnabled = [this](const QModelIndex &index) {
return !isIndexDragEnabled(index);
};showing error in this line " !isIndexDragEnabled(index) "