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

Drag.hotSpot has not effect on dynamically created drag objects

    XMLWordPrintable

Details

    • All

    Description

      In this example I have a DragHandler which will start a drag anywhere inside the window. The item that is being dragged is created on the fly when the drag starts.

      That works, but the hotSpot of the drag item is not respected - the cursor should be in the center of the item, not on the top left (see attached image).

      It works when the DragHandler is attached to an existing item which is then moved. I know I can do it like that in this example, but it is not possible in our "real" application where this occurs. So besides a fix, any workaround that still allows creation of the drag item on-the-fly is appreciated.

      import QtQuick
      
      Window {
          id: win
          width: 640
          height: 480
          visible: true
          title: "Sandbox"
      
          Text {
              anchors.centerIn: parent
              text: 'Start dragging anywhere'
          }
      
          DragHandler {
              id: dragHandler
              target: null
              onActiveChanged: () => {
                                   if (dragHandler.active) {
                                       const dragItem = dragComp.createObject(win);
                                       dragItem.x = dragHandler.centroid.position.x;
                                       dragItem.y = dragHandler.centroid.position.y;
                                       dragHandler.target = dragItem;
                                   } else {
                                       dragHandler.target.destroy();
                                       dragHandler.target = null;
                                   }
                               }
          }
      
      
          Component {
              id: dragComp
      
              Rectangle {
                  id: dragRect
                  color: 'red'
                  width: 60
                  height: 60
                  radius: 30
      
                  Drag.hotSpot: Qt.point(dragRect.width / 2, dragRect.height / 2)
              }
          }
      }
      

      Attachments

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            moerkb Markus Bader
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated: