PDA

View Full Version : filter mouse event



sajis997
7th February 2015, 10:50
Hello forum,

I have an opengl scene as an underlay and I want to do the camera movement with the mouse move event. Simultaneously I have couple of sliders in the scene as an overlay. I am having problem to filter between these two. The slider is disabled if I am doing the following :





import QtQuick 2.2
import QtQuick.Controls 1.1


Item {
id: root
width: 512; height: 512

................................
................................

}

//THE SLIDER IS SET HERE IN A GRID - omited for brevity

Rectangle {
id: rect
color: "red"
radius: 10
opacity: 0.1
border.color: "black"
focus: true
antialiasing: true
//the rectangle element
//will fill the whole layout
anchors.fill: controlContainer
}

//SOME TESTING RELATED MOUSE AREA
MouseArea
{
id: sceneMouseArea
anchors.fill: root
}

}





I believe that the root mouse area is over-lapping with the other items that functions with the mouse event. Is there any example/reference that demonstrates mouse event filtering techniques where all the events are caught and call the relevant functions accordingly ?


Thanks

anda_skoa
7th February 2015, 11:06
QtQuick items without explicit z value are ordered by appaerance in the file.

In your case the MouseArea is after the slider, meaning it is on top of it, thus getting mouse events before the slider does.

Try putting the mouse are below the slider.

Cheers,
_

sajis997
7th February 2015, 13:35
The solution that you suggested enables the slider the mouse event, but disables the mouse event over the root object - which is Item. I want to capture this mouse event as well - to move the camera in the underlying scene.

Thanks

sajis997
9th February 2015, 20:53
QtQuick items without explicit z value are ordered by appaerance in the file.

In your case the MouseArea is after the slider,
meaning it is on top of it_,

Which one is on top ?

anda_skoa
10th February 2015, 08:33
Item {
Item {
id: a
anchors.fill: parent
}
Item {
id: b
anchors.fill: parent
}
}

b is on top of a

Cheers,
_

sajis997
11th February 2015, 11:22
Hello ,

The issue is the new one , but related to the mouse event. That is whay I thought of keeping it in the same thread.

I am now rotating the opengl scene with the mouse event captured in the .qml file. I want to rotate the scene when the mouse is pressed and moved. In that case I am using the pressed and positionchanged signal as follows:



Item
{
id:root
width: 512
height: 512

RippleSceneItem
{
id: ripple
}

MouseArea
{
anchors.fill: root
//enable the mouse area
enabled: true
acceptedButtons: Qt.LeftButton |
Qt.RightButton |
Qt.MiddleButton
onPressed:
{
ripple.oldMouseX = mouse.x
ripple.oldMouseY = mouse.y

ripple.mousePressed = true
}

onReleased:
{
ripple.mousePressed = false
ripple.mouseMoved = false
}

onPositionChanged:
{
ripple.currentMouseX = mouse.x
ripple.currentMouseY = mouse.y
ripple.mouseMoved = true
}
}
}



As you can see I am sending a flag property
ripple.mouseMoved = true . I want to flag it to false when the mouse is pressed , but not moving. How to do it ?

anda_skoa
11th February 2015, 13:18
As you can see I am sending a flag property
ripple.mouseMoved = true . I want to flag it to false when the mouse is pressed , but not moving. How to do it ?



ripple.mouseMoved = false

sajis997
11th February 2015, 13:35
I wanted to mean that how to capture when the mouse is not moving. We do something when the mouse changes position as follows:



onPositionChanged :
{
/// do someting
}


Where to put
ripple.mouseMoved = false , because I did not find anything like onNotPositionChanged.

What is happening now is that - When I click on the scene and move a bit - then the opengl object rotates along . But the rotation does not stop when I stopped moving the mouse. I want to rotate only as long as the mouse is moving.

Any idea ?


Thanks

anda_skoa
12th February 2015, 07:17
I wanted to mean that how to capture when the mouse is not moving.

onPressed

Cheers,
_

sajis997
15th February 2015, 21:44
Let me rephrase again - I wanted to mean that how to capture when the mouse is not moving while left mouse button is pressed. Initially the mouse is pressed and the capture it as follows:



onPressed:
{
ripple.oldMouseX = mouse.x
ripple.oldMouseY = mouse.y

ripple.mousePressed = true
ripple.mouseMoved = false
}


Then I am moving while the mouse button is pressed. I am capturing it as follows:



onPositionChanged:
{
ripple.currentMouseX = mouse.x
ripple.currentMouseY = mouse.y
ripple.mouseMoved = true
ripple.mousePressed = true
}


Now I want to capture when the mouse stopped moving while the mouse button is pressed. How to capture it ? I am getting the following unexpected output with the above snippet:

"The scene keeps rotating even after i stopped moving the mouse while the mouse button is pressed." What I want to get is as follows:

"The scene only rotates when the mouse is moved while the mouse button is pressed."

anda_skoa
16th February 2015, 07:26
Let me rephrase again - I wanted to mean that how to capture when the mouse is not moving while left mouse button is pressed.

That's the state when the mouse button is first pressed.
Once you move, you are out of that state.


Now I want to capture when the mouse stopped moving while the mouse button is pressed.
If that was your original goal then it would have helped to ask that instead of what you've asked for.

Obviously there is no event associated with user stops moving the mouse, so you need to detect the absence of move events.
E.g. using a timer that gets reset on every move. If it fires there has been no move within the timer's interval.

Cheers,
_