The drag & drop function is not working properly.
1. first, I set the grid as below: ( Qt 5.15.9 )
spView->options().setDragEnabled( true );
spView->options().setDropEnabled( true );
spView->options().setDragDropMode( QAbstractItemView::DragDrop );
spView->options().setSupportedDropActions( Qt::CopyAction | Qt::MoveAction );
spView->options().setModelItemsDragEnabled( true );
connect( spView, &Qtitan::GridViewBase::startDragDrop, this, &QDlgExplorer::oo_grdLocal_startDragDrop );
connect( spView, &Qtitan::GridViewBase::endDragDrop, this, &QDlgExplorer::oo_grdLocal_endDragDrop );
connect( spView, &Qtitan::GridViewBase::checkDragDrop, this, &QDlgExplorer::oo_grdLocal_checkDragDrop );
connect( spView, &Qtitan::GridViewBase::dragDrop, this, &QDlgExplorer::oo_grdLocal_dragDrop );
2. startDragDrop and endDragDrop are called, but checkDragDrop and dragDrop are not.
Also, in startDragDrop
void QDlgExplorer::oo_grdLocal_startDragDrop( DragArgs* Args )
{ if
FUNC_OBJ_TO( logger, Args->row() );
viewClickTimer.stop();
auto data = new QMimeData;
data->setImageData( driveIcon );
Args->setMimeData( data );
Args->setSupportedDropActions( Qt::CopyAction | Qt::MoveAction );
Args->setDefaultDropAction( Qt::DropAction::CopyAction );
Args->setAccepted( true );
//Args->setHandled( true );
}
No matter what combination of setAccepted and sethandled you use above, the mouse cursor's icon will be banned when you start dragging.
3. endDragDrop is called, but the Args passed in always contain no value.
4. After debugging the internal code, I realized that QDrag::Exec always returns Qt::IgnoreAction. What is the reason for this?
5. If I change the value set in spView->options().setSupportedDropActions( Qt::CopyAction | Qt::MoveAction );; in 1) to Qt::InternalMove, the same happens.
What you want: Notification of Drag & Drop inside the Grid, notification when items inside the Grid are dragged and dropped outside the Grid (to another widget or another process (Desktop, Windows Explorer, etc.. ) ), notification when items are dragged and dropped into the Grid from inside or outside the Grid.