[英]Adjust translation speed of QML DragHandler
我的問題是關於使用 QML DragHandler移動 QML 項目。 我已經通過拖動(按住 Ctrl 修飾符時)成功實現了 position,如下所示:
DragHandler {
dragThreshold: 0
acceptedModifiers: Qt.ControlModifier
}
現在我想添加另一個處理程序,它允許我精確地 position 元素。 其他軟件通過使用移位修飾符來做到這一點。 所以我想要做的是移動元素不是通過鼠標移動的像素量,而是比那個更小的量。 理想情況下,我想做這樣的事情:
DragHandler {
dragThreshold: 0
acceptedModifiers: Qt.ShiftModifier
onActiveTranslationChanged: {
activeTranslation *= 0.5;
}
}
不幸的是activeTranslation
是只讀的,我看不到任何其他我可以使用的屬性,我想不出任何其他方式來做到這一點......有人有想法嗎?
非常感謝您!
不幸的是 Qt 沒有提供任何方法來改變拖動速度 AFAIK。
但這是實現它的一種方法:
Rectangle
{
id: theDraggableElement
width: 100
height: width
color: "red"
DragHandler
{
id: dragHandlerFast
dragThreshold: 0
acceptedModifiers: Qt.ControlModifier
target: theDraggableElement
}
}
Item
{
id: invisibleItemForSlowDragging
width: theDraggableElement.width
height: theDraggableElement.height
Binding { restoreMode: Binding.RestoreBinding; when: !dragHandlerSlow.active; target: invisibleItemForSlowDragging; property: "x"; value: theDraggableElement.x }
Binding { restoreMode: Binding.RestoreBinding; when: !dragHandlerSlow.active; target: invisibleItemForSlowDragging; property: "y"; value: theDraggableElement.y }
DragHandler
{
id: dragHandlerSlow
dragThreshold: 0
acceptedModifiers: Qt.ShiftModifier
target: invisibleItemForSlowDragging
onTranslationChanged:
{
theDraggableElement.x = invisibleItemForSlowDragging.x - dragHandlerSlow.translation.x / 2
theDraggableElement.y = invisibleItemForSlowDragging.y - dragHandlerSlow.translation.y / 2
}
}
}
我已經用 Qt 5.15.2 對此進行了測試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.