PDA

View Full Version : Override the "no drop sign" when doing drag to desktop



thejester
6th December 2009, 20:37
Hi,

I would like to implement behaviour like in latest versions of firefox, where a user can drag a tab to the desktop and a new application is started.

I've almost figured out all i need to make it happen except for the "stop sign" that appears under the cursor when dragging stuff to the desktop...

In the code, i have the following mousemove event where the drag is implemented:


void CMyTabBar::mouseMoveEvent(QMouseEvent *event)
{

if (!(event->buttons() & Qt::LeftButton))
{
// Wrong buttn, no drag
return;
}
if ((event->pos() - dragStartPosition).manhattanLength() < QApplication::startDragDistance())
{
// Distance too small, no drag yet !
return;
}

if (event->buttons() & Qt::LeftButton )
{
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
QPixmap* pixmap = new QPixmap(100,100);

pixmap->grabWidget( this );

drag->setMimeData(mimeData);
drag->setPixmap( *pixmap );

Qt::DropAction dropAction = drag->exec(Qt::MoveAction);

QWidget* t = drag->target () ;
if( t )
{
// there is a target....
}
else
{
// no target...
QWidget* tmp = new SomeWidget();
tmp->show();

}
delete drag;
delete pixmap;
}
}


Any ideas on how to override or remove the stop-sign below the cursor ?

Thanks !

squidge
6th December 2009, 21:55
Have you tried adding a Shell IDList Array to your mimedata? It's an array of PIDLs uniquely identifying the object/s. The shelll always uses objects rather than files or other things as they can specify virtual files and folders.

thejester
7th December 2009, 07:51
Hi, thanks for your reply.

How would i do that ?

Use void setMimeData ( QMimeData * data )
on the QDrag, with a subclass of QMimeData ... but fill it with what ?

squidge
7th December 2009, 08:10
http://msdn.microsoft.com/en-us/library/bb776902%28VS.85%29.aspx#CFSTR_SHELLIDLIST

thejester
7th December 2009, 11:07
how would you do this ?
You have to give me more to go on.... :)

squidge
7th December 2009, 11:41
Ok, create a QByteArray, fill it in like it says via that link, and then pass it to QMimeData::setData with a type of "Shell IDList Array". The data depends on what you want to transfer to the shell object (what you are dragging).

If you want source code of how to do that, well, Firefox is open-source :) Qt classes will not help you here.