Results 1 to 11 of 11

Thread: filter mouse event

  1. #1
    Join Date
    Jan 2011
    Posts
    212
    Thanks
    24
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default filter mouse event

    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 :


    Qt Code:
    1. import QtQuick 2.2
    2. import QtQuick.Controls 1.1
    3.  
    4.  
    5. Item {
    6. id: root
    7. width: 512; height: 512
    8.  
    9. ................................
    10. ................................
    11.  
    12. }
    13.  
    14. //THE SLIDER IS SET HERE IN A GRID - omited for brevity
    15.  
    16. Rectangle {
    17. id: rect
    18. color: "red"
    19. radius: 10
    20. opacity: 0.1
    21. border.color: "black"
    22. focus: true
    23. antialiasing: true
    24. //the rectangle element
    25. //will fill the whole layout
    26. anchors.fill: controlContainer
    27. }
    28.  
    29. //SOME TESTING RELATED MOUSE AREA
    30. MouseArea
    31. {
    32. id: sceneMouseArea
    33. anchors.fill: root
    34. }
    35.  
    36. }
    To copy to clipboard, switch view to plain text mode 


    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

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: filter mouse event

    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,
    _

  3. #3
    Join Date
    Jan 2011
    Posts
    212
    Thanks
    24
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: filter mouse event

    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

  4. #4
    Join Date
    Jan 2011
    Posts
    212
    Thanks
    24
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: filter mouse event

    QtQuick items without explicit z value are ordered by appaerance in the file.

    In your case the MouseArea is after the slider,
    Quote Originally Posted by anda_skoa View Post
    meaning it is on top of it_
    ,

    Which one is on top ?

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: filter mouse event

    Qt Code:
    1. Item {
    2. Item {
    3. id: a
    4. anchors.fill: parent
    5. }
    6. Item {
    7. id: b
    8. anchors.fill: parent
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 
    b is on top of a

    Cheers,
    _

  6. The following user says thank you to anda_skoa for this useful post:

    sajis997 (11th February 2015)

  7. #6
    Join Date
    Jan 2011
    Posts
    212
    Thanks
    24
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: filter mouse event

    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:

    Qt Code:
    1. Item
    2. {
    3. id:root
    4. width: 512
    5. height: 512
    6.  
    7. RippleSceneItem
    8. {
    9. id: ripple
    10. }
    11.  
    12. MouseArea
    13. {
    14. anchors.fill: root
    15. //enable the mouse area
    16. enabled: true
    17. acceptedButtons: Qt.LeftButton |
    18. Qt.RightButton |
    19. Qt.MiddleButton
    20. onPressed:
    21. {
    22. ripple.oldMouseX = mouse.x
    23. ripple.oldMouseY = mouse.y
    24.  
    25. ripple.mousePressed = true
    26. }
    27.  
    28. onReleased:
    29. {
    30. ripple.mousePressed = false
    31. ripple.mouseMoved = false
    32. }
    33.  
    34. onPositionChanged:
    35. {
    36. ripple.currentMouseX = mouse.x
    37. ripple.currentMouseY = mouse.y
    38. ripple.mouseMoved = true
    39. }
    40. }
    41. }
    To copy to clipboard, switch view to plain text mode 

    As you can see I am sending a flag property
    Qt Code:
    1. ripple.mouseMoved = true
    To copy to clipboard, switch view to plain text mode 
    . I want to flag it to false when the mouse is pressed , but not moving. How to do it ?

  8. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: filter mouse event

    Quote Originally Posted by sajis997 View Post
    As you can see I am sending a flag property
    Qt Code:
    1. ripple.mouseMoved = true
    To copy to clipboard, switch view to plain text mode 
    . I want to flag it to false when the mouse is pressed , but not moving. How to do it ?
    Qt Code:
    1. ripple.mouseMoved = false
    To copy to clipboard, switch view to plain text mode 

  9. #8
    Join Date
    Jan 2011
    Posts
    212
    Thanks
    24
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: filter mouse event

    I wanted to mean that how to capture when the mouse is not moving. We do something when the mouse changes position as follows:

    Qt Code:
    1. onPositionChanged :
    2. {
    3. /// do someting
    4. }
    To copy to clipboard, switch view to plain text mode 

    Where to put
    Qt Code:
    1. ripple.mouseMoved = false
    To copy to clipboard, switch view to plain text mode 
    , 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

  10. #9
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: filter mouse event

    Quote Originally Posted by sajis997 View Post
    I wanted to mean that how to capture when the mouse is not moving.
    onPressed

    Cheers,
    _

  11. #10
    Join Date
    Jan 2011
    Posts
    212
    Thanks
    24
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: filter mouse event

    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:

    Qt Code:
    1. onPressed:
    2. {
    3. ripple.oldMouseX = mouse.x
    4. ripple.oldMouseY = mouse.y
    5.  
    6. ripple.mousePressed = true
    7. ripple.mouseMoved = false
    8. }
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. onPositionChanged:
    2. {
    3. ripple.currentMouseX = mouse.x
    4. ripple.currentMouseY = mouse.y
    5. ripple.mouseMoved = true
    6. ripple.mousePressed = true
    7. }
    To copy to clipboard, switch view to plain text mode 

    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."

  12. #11
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: filter mouse event

    Quote Originally Posted by sajis997 View Post
    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.

    Quote Originally Posted by sajis997 View Post
    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,
    _

Similar Threads

  1. Replies: 3
    Last Post: 7th January 2012, 08:38
  2. Event filter with mouse events
    By felo188 in forum Qt Programming
    Replies: 13
    Last Post: 22nd July 2011, 10:57
  3. Event filter question
    By d_stranz in forum Qt Programming
    Replies: 7
    Last Post: 7th July 2011, 23:08
  4. problem with event filter compile for S60
    By jimiq in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 6th July 2010, 19:48
  5. Event Filter & No Focus problem
    By AlexanderPopov in forum Newbie
    Replies: 0
    Last Post: 22nd December 2009, 20:15

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.