Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
6.6.1
-
None
Description
Under Linux custom cursors created with QDrag::setDragCursor are shown at a wrong position: The hotspot is always the center of the pixmap. The same call works well with Windows, where the hotspot is the top/left corner. Reason is, that QBasicDrag::updateCursor (qsimpledrag.cpp) creates the cursor with the default hotspot position, whereas QWindowsOleDropSource::createCursors (qwindowsdrag.cpp) calculates an exact hotspot position:
if (hasPixmap) { const int x1 = qMin(-hotSpot.x(), 0); const int x2 = qMax(scaledPixmap.width() - hotSpot.x(), cursorPixmap.width()); const int y1 = qMin(-hotSpot.y(), 0); const int y2 = qMax(scaledPixmap.height() - hotSpot.y(), cursorPixmap.height()); QPixmap newCursor(x2 - x1 + 1, y2 - y1 + 1); newCursor.fill(Qt::transparent); QPainter p(&newCursor); const QPoint pmDest = QPoint(qMax(0, -hotSpot.x()), qMax(0, -hotSpot.y())); p.drawPixmap(pmDest, scaledPixmap); p.drawPixmap(qMax(0, hotSpot.x()),qMax(0, hotSpot.y()), cursorPixmap); newPixmap = newCursor; newHotSpot = QPoint(qMax(0, hotSpot.x()), qMax(0, hotSpot.y())); }
In order to give the user full control over the position of the hotspot, I suggest to add a further function to QDrag:
QDrag::setDragCursor(const QCursor &cursor, Qt::DropAction action)
(but in that case QCursor should support negative hotspot coordinates)