[Qt-interest] QDrag::setDragCursor- what does it do?

John Weeks john at wavemetrics.com
Thu Jun 23 01:10:54 CEST 2011


The description of QDrag::setDragCursor suggests that it might change the mouse pointer while a drag is in progress. But no matter what I do, the cursor remains the arrow cursor. Does this call do something different from what I think it does?

Here's the code I'm using to initiate dragging. It works well, except that I'd really like to hide the pointing arrow while dragging, and just have the pixmap I set using QDrag->setPixmap(). I'm using Qt::OpenHandCursor just for testing, so that if something happens, I'll be able to see it. 

void InfoWindowCursorButton::mouseMoveEvent ( QMouseEvent * event )
{
	if ((event->pos() - clickPosition).manhattanLength() < QApplication::startDragDistance())
		return;				// no drag unless movement is greater than the standard drag start distance
	
	event->accept();
	
	QDrag *drag = new QDrag(this);
	QMimeData *mimeData = new QMimeData;

	QByteArray data(1, 'A'+cursorType);
	mimeData->setData("application/x-wavemetrics-cursordata", data);
	drag->setMimeData(mimeData);

	QString cursorFile;
	QString cursorMaskFile;
	if (cursorType & 1)
	{
		cursorFile = ":/Cursors/Cursors/CursorBoxGraph.png";
		cursorMaskFile = ":/Cursors/Cursors/CursorBoxGraphMask.png";
	}
	else
	{
		cursorFile = ":/Cursors/Cursors/CursorCircleGraph.png";
		cursorMaskFile = ":/Cursors/Cursors/CursorCircleGraphMask.png";
	}
	QPixmap dragpic(cursorFile);
	QBitmap dragmask(cursorMaskFile);
	dragpic.setMask(dragmask);
	drag->setPixmap(dragpic);
	QPoint hotspot(8,8);
	drag->setHotSpot(hotspot);
	QCursor cursor(Qt::OpenHandCursor);
	drag->setDragCursor(cursor.pixmap(), Qt::MoveAction);

	Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::MoveAction);		// "copy" and "move" have no meaning here
}

Thanks!
John Weeks

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110622/5c9d5a74/attachment.html 


More information about the Qt-interest-old mailing list