我想反轉滑鼠游標的方向。例如,當我向右移動滑鼠時 - 游標向左移動,當我向上移動滑鼠時 - 游標向下移動。如果滑鼠按下左鍵,我想這樣做。
uj5u.com熱心網友回復:
您可以隱藏真實游標并將假游標放置在不同的位置。在以下示例中:
- A 定義
Rectangle反向滑鼠區域適用的位置 MouseArea需要containsMouse和激活模式pressed之前reverseMouseArea隱藏真正的滑鼠Qt.BlankCursor- 將使用滑鼠游標的 SVG 娛樂顯示假滑鼠
- 當啟用反向模式時,我們用
parent.width - mouseArea.mouseX和翻轉假滑鼠的坐標parent.height - mouseArea.mouseY
import QtQuick
import QtQuick.Controls
Page {
Rectangle {
anchors.centerIn: parent
color: "#ffe"
border.color: "grey"
width: Math.floor(parent.width / 2)
height: Math.floor(parent.height / 2)
Image {
id: fakeMouse
x: mouseArea.reversed
? parent.width - mouseArea.mouseX
: mouseArea.mouseX
y: mouseArea.reversed
? parent.height - mouseArea.mouseY
: mouseArea.mouseY
visible: mouseArea.containsMouse
source: "cursor-32.svg"
}
MouseArea {
id: mouseArea
property bool reversed: pressed & containsMouse
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.BlankCursor
}
Frame {
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom
anchors.margins: 10
visible: fakeMouse.visible
Label {
text: fakeMouse.x " " fakeMouse.y
}
}
}
}
//cursor-32.svg
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><path d="M9 25.282l4.3-5.894 4.062 8.043 5.016-2.523L18.416 17h7.01L9 5.016zm.99-18.318l12.398 9.046h-5.575l4.237 8.457-3.25 1.635-4.346-8.606-3.464 4.749z"/><path fill="none" d="M0 0h32v32H0z"/></svg>
您可以在線試用!
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/520146.html
標籤:qtqml
