Return the mouse position to its previous configurable location in QML?
-
I wrote a code that when pressed and hold left bottom hide cruises the mouse, and changes the value of a variable as the mouse changes position. Once the mouse is released, the mouse should appear where it was hidden. I checked all the properties of the MouseArea but it did not work.
-
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")id: hhhhh property int name: 0 property alias curso: mous.cursorShape property bool cursorPosActive : false property bool shift : false property point cursorPos property bool pox_logic: false //property bool xxx: false property real step_shift: 2 property point startFlickContentRef: Qt.point(0, 0) property point startFlickMousePos: Qt.point(mous.mouseX, mous.mouseY) property bool flicking: false MouseArea { function setText(event) { var the_key = event.key if (the_key === Qt.Key_Shift) return true return false } Keys.onPressed: shift = setText(event) id:mous onExited: { cursorPosActive = false } onPositionChanged: { // MouseEvent OK if(pox_logic === true){ console.log(mouse.x + " " + mouse.y); } if(shift) console.log((mouse.x * step_shift) + " " + (mouse.y * step_shift)); } onEntered: { // here: mouseX/Y OK? cursorPos = Qt.point(mouseX, mouseY) cursorPosActive = true } onClicked: { // MouseEvent OK cursorPos = Qt.point(mouse.x, mouse.y) } onPressAndHold: { startFlickContentRef = Qt.point(mous.mouseX, mous.mouseY) // console.log(startFlickContentRef.x + " " + startFlickContentRef.y); curso = Qt.BlankCursor pox_logic= true cursorPos = Qt.point(mouse.x, mouse.y) } onReleased: {mous.moveCursor()}
// curso = Qt.ArrowCursor
// pox_logic =false
// // mouseXChanged() = startFlickContentRef.x
// // mouse.y = startFlickContentRef.y
// mous.moveCursor();//// mouseX: startFlickContentRef.x
//// mouseY: startFlickContentRef.y
// anchors.fill: parent
// //enabled: false
// hoverEnabled: true
// cursorShape:Qt.ArrowCursor
// }//MouseArea
// MouseArea {
// width:startFlickContentRef.y; height: startFlickContentRef.x
// // onClicked: console.log("irregular area clicked")
}
} -
Hello @Saeed_Nowroozi. I don't really know if what you want to do is available in QML. However, there is something in qt called "event filters": https://doc.qt.io/archives/4.6/eventsandfilters.html. You can create an event filter as shown in the link to filter mouse events and either let the application handle them or not. In your case, you may want to create some sort of variable that gets changed when you hide the mouse and stop all mouse navigation related events. If you have any other questions please let me know and I'll try my best to help you.