I do have an app with a treeWidget supporting Drag n Drop.
I'm trying to highlight an item during the drag'n drop action. When dragging a file and before dropping it, I would like to highlight the destination item.
void TreeView::dragMoveEvent(QDragMoveEvent * event)
{
qDebug() << "On Drag Move Event";
const QMimeData* mimeData = event->mimeData();
event->setDropAction(Qt::CopyAction);
if (mimeData->hasUrls())
{
QTreeWidgetItem *item = itemAt(event->pos());
if(item) {
qDebug() << "itemat: " << item->text(0);
setStyleSheet(QString::fromUtf8("QTreeWidget::item:hover {\n"
"background-color: rgb(123, 45, 67);\n"
"}"));
}
event->setDropAction(Qt::CopyAction);
event->acceptProposedAction();
}
else
event->ignore();
// dropSite = event->answerRect();
// event->acceptProposedAction();
}
Funny things, it highlight the item but after.. it's like the DnD allow to setup the model and after he keep it for the overall behaviour. I'm expecting the highlight during the DnD but not during the normal use. By normal use, I mean just have the mouse getting over with any files to DnD.
The highlight is expected with DnD (a content is selected by clich and move to/from items)
I also have 3 column but only items in the 1st column are highlighted.
The current code is highlighting the items but after the DnD not during even if it's done in dragMoveEvent
Any ideas ?