PDA

View Full Version : QListWidget Drag and Drop problem



winkle99
20th October 2009, 20:00
Hi,

I'm working on a project where I need to drag data from one QListWidget to another and I'm missing something simple. When I select an item to drag it's being marked/displayed as forbidden. I'm stumped as to why.

I have a class derived from QListWidget. In the constructor I set:



setDragEnabled( true );
viewport()->setAcceptDrops( true );
setDragDropMode( QAbstractItemView::DragDrop );
setDropIndicatorShown( true );

I've derived a mousePressEvent method which I'm keeping really simple at this point:

void ModifyParamSetListWidget::mousePressEvent( QMouseEvent *event )
{
QListWidgetItem *anItem = itemAt( event->pos() );
if ( !anItem )
{
event->ignore();
QListWidget::mousePressEvent( event);
return;
}
if ( event->button() == Qt::LeftButton )
{
QDrag *drag = new QDrag( this );
QMimeData *mimeData = new QMimeData;
mimeData->setText( anItem->data( Qt::DisplayRole).toString() );
drag->setMimeData( mimeData );
Qt::DropAction dropAction = drag->exec( Qt::CopyAction );
}
else
{
QListWidget::mousePressEvent( event );
}
return;
}

I'm just adding adding standard list widget items to the list.


QListWidgetItem *item = new QListWidgetItem();
item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsDragEnabled );
item->setText( itsName );

The problem I'm having is that when I select an item in the list to drag it's being marked as forbidden. I can't figure out what I've missed. I think it's something simple and obvious I'm just missing it. Can anyone help me out here?

thanks