View Full Version : Hide drag and drop icon

16th June 2014, 20:29
Hi all,
When you drag and drop from a QListView or QTreeView you have the cursor + the icon or the row of the tree.
Is it possible to hide and only keep the cursor when the drag and drop is in a QWidget ?
Thanks for the help

17th June 2014, 03:44
Does QDrag::setPixmap() with an empty QPixmap do it?

17th June 2014, 04:47
Thanks, that works using this code :

class CListView : public QListView

CListView( QWidget* Parent ) :
QListView( Parent )


virtual void startDrag( Qt::DropActions supportedActions )
QDrag Drag( this );
const QModelIndexList indexes = selectedIndexes();
Drag.setMimeData( model()->mimeData( indexes ) );
Drag.exec( supportedActions );

Is it possible to only hide the pixmap when it's outside of the QListView ?
Maybe "dragLeaveEvent ( QDragLeaveEvent * e )" is a way to think about but then "QDrag Drag( this );" has to be stored ?
But still the problem of "m_DetailList->setViewMode( QListView::IconMode );".
It's impossible to drag and drop internaly using QListView with IconMode.
Using "QListView::ListMode" that works normally.
I hope you know the solution.

EDIT : Apparently it's because "m_DetailList->setMovement( QListView::Static );"
But without it, you can move items that is not good for what I do, does a way exist to just allow drag and drop but not move ?

EDIT2 : Here the solution of the Static problem :

m_DetailList->setMovement( QListView::Snap );

virtual void dropEvent( QDropEvent* e )
if( indexAt( e->pos() ).isValid() )
QListView::dropEvent( e );

I do all that under your control, say me if what I do is not correct.