Problem with a cursor during Drag and Drop
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
Code:
//we do not need to distinguish click from a drag
//and we implement drag mechanism in a mousePressEvent
QPoint clickPt
= event
->pos
();
//we recognize color of the dragged item
int pawnKind = -1; //index of a global pawn vector
for(int i=0;i<4;++i) {
pawnArea.setRect(25,45+i*30,20,20);
if(pawnArea.contains(clickPt)) { pawnKind = i; break; }
pawnArea.setRect(55,45+i*30,20,20);
if(pawnArea.contains(clickPt)) { pawnKind = i+4; break; }
}
//if a click happened on a non-pawn area we ignore it
if(pawnKind == -1) return;
qDebug
(qPrintable
(QString::number(pawnKind
)));
//we assign the QColor object to a QByteArray
out << internalVectorPtr->at(pawnKind);
//we pack it
mimeData->setData("qt-class/qcolor", bytes);
//we prepare cursor graphics
draggedPawnImage.fill(Qt::transparent);
Pawn tmpPawn = Pawn(internalVectorPtr->at(pawnKind));
MTR::Global::paintPawnAt(2,2,tmpPawn,pixPainter);
//we establish QDrag object, draw cursor and embed data
drag->setPixmap(draggedPawnImage);
//QApplication::setOverrideCursor(QCursor(*cursorPx,10,10));
drag->setDragCursor(*cursorPx,Qt::MoveAction);
drag->setDragCursor(*cursorPx,Qt::CopyAction);
drag->setMimeData(mimeData);
drag
->setHotSpot
(QPoint(12,
12));
//and we send it
Qt::DropAction dropAction = drag->exec(Qt::CopyAction,Qt::CopyAction);
//QApplication::restoreOverrideCursor();
}
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:
Code:
//we prepare small point-pixmap which will be our mini cursor when dragging a pawn
cursorPx->fill();
there is Qt::ForbiddenCursor.
How to establish desired cursor during drag and drop?
Re: Problem with a cursor during Drag and Drop
You'll see a forbidden cursor over everything that does not accept the proposed action of QDragMoveEvent.
Code:
{
if (event->mimeData()->hasFormat("qt-class/qcolor"))
event->acceptProposedAction();
}