6

In the following example I would expect that onDragStarted / onDragFinished are called when one rectangle is dragged. However only drag.onActiveChanged (of the mouseArea) and Drag.onActiveChanged (of the rectangle are called). I get the expected output when setting Drag.dragType to Drag.Automatic but then I don't see the rectangle anymore. I am using Qt 5.5 on a Mac (El Capitan).

import QtQuick 2.5
import QtQuick.Window 2.2

Window {
  visible: true

  width: 100
  height: 200

  ListModel {
    id: testModel
    ListElement { name: "red";   value: "#f00" }
    ListElement { name: "green"; value: "#0f0" }
    ListElement { name: "blue";  value: "#00f" }
  }

  Component {
    id: rect
    Rectangle {

      Drag.active: mouseArea.drag.active
      Drag.hotSpot.x: width / 2
      Drag.hotSpot.y: height / 2
      //Drag.dragType: Drag.Automatic

      Drag.onActiveChanged: {
        console.log("Active changed..")
      }

      Drag.onDragStarted: {
        console.log("Drag started..")
      }

      Drag.onDragFinished: {
        console.log("Drag finished!")
      }

      MouseArea {
        id: mouseArea

        anchors.fill: parent
        hoverEnabled: true
        drag.target: parent

        drag.onActiveChanged: {
          console.log("Drag prop became active..")
        }

        onClicked: {
          colorButtonClicked(buttonName, buttonColor);
        }
      }

      width: 80
      height: 20
      radius: 6
      color: model.value
    }
  }

  Column {
    spacing: 3
    anchors.centerIn: parent
    Repeater {
      model: testModel
      delegate: rect
    }
  }
}
Nils
  • 13,319
  • 19
  • 86
  • 108

1 Answers1

6

I was puzzled about the same problem based on my assumptions from the signal names, but a look at the documentation showed that the signals will only work when using Drag.Automatic or explicitly calling startDrag.

dragStarted()

This signal is emitted when a drag is started with the startDrag() method or when it is started automatically using the dragType property.

dragFinished(DropAction action)

This signal is emitted when a drag finishes and the drag was started with the startDrag() method or started automatically using the dragType property.

The other issue seen when using Drag.Automatic appears to be fixed in Qt 5.6.1

Community
  • 1
  • 1
Kim
  • 728
  • 10
  • 20
  • Thanks for your answer, I have to upgrade Qt on my Macbook and test it again at some point. – Nils Sep 07 '16 at 15:11