@@ -594,18 +594,26 @@ void CFavoriteView::mousePressEvent(QMouseEvent *event)
594594 qDebug (log) << " mousePressEvent" ;
595595 if (m_pTreeView && m_pTreeView->selectionModel ()
596596 && event->button () == Qt::LeftButton) {
597+
597598 // 获取选中的索引
598599 QModelIndexList indexes = m_pTreeView->selectionModel ()->selectedIndexes ();
599600 if (!indexes.isEmpty ()) {
600- QDrag *drag = new QDrag (this );
601- do {
602- if (!drag) break ;
603- m_DragStartPosition = event->pos ();
604- CFavoriteMimeData *pData = new CFavoriteMimeData ();
605- pData->m_Items = indexes;
606- drag->setMimeData (pData);
607- Qt::DropAction dropAction = Qt::MoveAction;
608- /*
601+
602+ #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
603+ auto curIndex = m_pTreeView->indexAt (event->position ().toPoint ());
604+ #else
605+ auto curIndex = m_pTreeView->indexAt (event->pos ());
606+ #endif
607+ if (indexes.contains (curIndex)) {
608+ QDrag *drag = new QDrag (this );
609+ do {
610+ if (!drag) break ;
611+ m_DragStartPosition = event->pos ();
612+ CFavoriteMimeData *pData = new CFavoriteMimeData ();
613+ pData->m_Items = indexes;
614+ drag->setMimeData (pData);
615+ Qt::DropAction dropAction = Qt::MoveAction;
616+ /*
609617 if(event->modifiers() & Qt::ControlModifier) {
610618 dropAction = Qt::CopyAction;
611619 // 设置拖拽时的光标
@@ -615,10 +623,11 @@ void CFavoriteView::mousePressEvent(QMouseEvent *event)
615623 // size = icon.availableSizes().at(0);
616624 // drag->setDragCursor(icon.pixmap(size), Qt::MoveAction);
617625 }//*/
618- drag->exec (dropAction);
619- } while (0 );
620- if (drag)
621- delete drag;
626+ drag->exec (dropAction);
627+ } while (0 );
628+ if (drag)
629+ delete drag;
630+ }
622631 }
623632 }
624633 QWidget::mousePressEvent (event);
0 commit comments