Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-120228

Custom cursors are shown at a wrong position (Linux)

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 6.6.1
    • GUI: Drag and Drop
    • None
    • Linux/X11

    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)

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            liaqi Liang Qi
            wschenke Winfried Schenke
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes