首页 > 解决方案 > 如何修复在拖动时切换按下的鼠标按钮时发生的卡住 QML 拖动

问题描述

我们遇到了当用户在拖动时切换按下的鼠标按钮时,在 QML 中拖动可能会卡住的问题。

我附上了一个最小的例子,它基本上是文档文档中给出的例子。

有人能够确认这种行为吗?

和/或能够暗示该问题的解决方案?

干杯托比

我们正在使用 Qt5.12.11

import QtQuick 2.5

Rectangle {
  id: rootDialog

  anchors.fill: parent
  anchors.margins: 5
  border.width: 1
  color: "#11ffffff"

  Rectangle {
    id: root
    color: "green"

    property string colorKey: "yellow"

    width: 64; height: 64

    MouseArea {
      id: mouseArea

      width: 64; height: 64
      anchors.centerIn: parent

      drag.target: tile

      onReleased: parent = tile.Drag.target !== null ? tile.Drag.target : root

      acceptedButtons: Qt.LeftButton //we only want the dragging to happen with the left mouse button

      Rectangle {
        id: tile

        width: 64; height: 64
        anchors.verticalCenter: parent.verticalCenter
        anchors.horizontalCenter: parent.horizontalCenter

        color: root.colorKey

        Drag.keys: [ root.colorKey ]
        Drag.active: mouseArea.drag.active
        Drag.hotSpot.x: 32
        Drag.hotSpot.y: 32
        states: State {
            when: mouseArea.drag.active
            ParentChange { target: tile; parent: root }
            AnchorChanges { target: tile; anchors.verticalCenter: undefined; anchors.horizontalCenter: undefined }
        } //states
      } //Rectangle
    } //MouseArea
  } //Rectangle
} //Rectangle

标签: qtdrag-and-dropqml

解决方案


推荐阅读