Hi,
I have got a tiny problem connected to a drag and drop mechanism.
My QWidget subclass (lets call it A) is intended to be a source of elements that are copied to other type of QWidget subclass(lets call it B), thus in A I reimplement only
Qt Code:
  1. void PawnBox::mousePressEvent(QMouseEvent *event) {
  2. //we do not need to distinguish click from a drag
  3. //and we implement drag mechanism in a mousePressEvent
  4. QPoint clickPt = event->pos();
  5. //we recognize color of the dragged item
  6. QRect pawnArea = QRect(0,0,20,20);
  7. int pawnKind = -1; //index of a global pawn vector
  8. for(int i=0;i<4;++i) {
  9. pawnArea.setRect(25,45+i*30,20,20);
  10. if(pawnArea.contains(clickPt)) { pawnKind = i; break; }
  11. pawnArea.setRect(55,45+i*30,20,20);
  12. if(pawnArea.contains(clickPt)) { pawnKind = i+4; break; }
  13. }
  14. //if a click happened on a non-pawn area we ignore it
  15. if(pawnKind == -1) return;
  16. qDebug(qPrintable(QString::number(pawnKind)));
  17. //we assign the QColor object to a QByteArray
  18. QByteArray bytes;
  19. QDataStream out(&bytes,QIODevice::WriteOnly);
  20. out << internalVectorPtr->at(pawnKind);
  21. //we pack it
  22. QMimeData *mimeData = new QMimeData;
  23. mimeData->setData("qt-class/qcolor", bytes);
  24. //we prepare cursor graphics
  25. QPixmap draggedPawnImage = QPixmap(24,24);
  26. draggedPawnImage.fill(Qt::transparent);
  27. QPainter pixPainter(&draggedPawnImage);
  28. Pawn tmpPawn = Pawn(internalVectorPtr->at(pawnKind));
  29. MTR::Global::paintPawnAt(2,2,tmpPawn,pixPainter);
  30. //we establish QDrag object, draw cursor and embed data
  31. QDrag *drag = new QDrag(this);
  32. drag->setPixmap(draggedPawnImage);
  33. //QApplication::setOverrideCursor(QCursor(*cursorPx,10,10));
  34. drag->setDragCursor(*cursorPx,Qt::MoveAction);
  35. drag->setDragCursor(*cursorPx,Qt::CopyAction);
  36. drag->setMimeData(mimeData);
  37. drag->setHotSpot(QPoint(12,12));
  38. //and we send it
  39. Qt::DropAction dropAction = drag->exec(Qt::CopyAction,Qt::CopyAction);
  40. //QApplication::restoreOverrideCursor();
  41.  
  42. }
To copy to clipboard, switch view to plain text mode 
and everything is fine apart from the fact that over a pawn image instead of a small and transparent dot of *cursorPx initialized in a constructor of A:
Qt Code:
  1. //we prepare small point-pixmap which will be our mini cursor when dragging a pawn
  2. cursorPx = new QPixmap(1,1);
  3. cursorPx->fill();
To copy to clipboard, switch view to plain text mode 
there is Qt::ForbiddenCursor.

How to establish desired cursor during drag and drop?