Results 1 to 13 of 13

Thread: How to detect hover events when mouse button is pressed

  1. #1
    Join Date
    Dec 2007
    Location
    London
    Posts
    206
    Thanks
    40
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default How to detect hover events when mouse button is pressed

    Hello,

    Is there any straightforward way to detect "hoverEnterEvent" of a QGraphicsItem object when mouse button is pressed.

    When mouse button is pressed none of hover events are detected.

    Thanks..
    Yigit

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to detect hover events when mouse button is pressed

    You have to ask for the hover events to be sent by setting an appropriate flag on your item.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Dec 2007
    Location
    London
    Posts
    206
    Thanks
    40
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: How to detect hover events when mouse button is pressed

    I couldnt find any related flag. Is there one? In the documentation it is said that:

    Hover events are delivered when there is no current mouse grabber item
    I couldnt find a way to deliver the event when there is a mouse grabber.(mouse pressed)

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to detect hover events when mouse button is pressed

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Dec 2007
    Location
    London
    Posts
    206
    Thanks
    40
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: How to detect hover events when mouse button is pressed

    Ok ;but setAcceptHoverEvents is valid only for the cases where mouse button is not pressed.

    My problem is that: When you press the mouse button "outside" of the bounding rectangle of the QGraphicsItem and after that move on the item, no hoverEvents are detected.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to detect hover events when mouse button is pressed

    Quote Originally Posted by yagabey View Post
    Ok ;but setAcceptHoverEvents is valid only for the cases where mouse button is not pressed.
    When the button is pressed, you get mouse events -- mousePressEvent, mouseMoveEvent and mouseReleaseEvent.

    My problem is that: When you press the mouse button "outside" of the bounding rectangle of the QGraphicsItem and after that move on the item, no hoverEvents are detected.
    That's because they are not hover events. If you press the mouse button and hold it, the item (or scene) becomes the "grabber item" and all mouse events are delivered only to that item.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. The following user says thank you to wysota for this useful post:

    yagabey (21st May 2011)

  8. #7
    Join Date
    Dec 2007
    Location
    London
    Posts
    206
    Thanks
    40
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: How to detect hover events when mouse button is pressed

    Ok thanks. So it means that there is no way to detect hover events if some other item is the grabber item..Right?

  9. #8
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to detect hover events when mouse button is pressed

    Quote Originally Posted by yagabey View Post
    Ok thanks. So it means that there is no way to detect hover events if some other item is the grabber item..Right?
    There is NO SUCH THING as a hover event when mouse button is pressed; there are only selection or drag events.

    If you want to perform mouse TRACKING, there is a setting for that in the Widget class; it is disabled by default. You will be responsible for passing mouse events along if you don't consume them yourself.

  10. #9
    Join Date
    Dec 2007
    Location
    London
    Posts
    206
    Thanks
    40
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: How to detect hover events when mouse button is pressed

    If you want to perform mouse TRACKING, there is a setting for that in the Widget class
    I am dealing with QGraphicsItem. Since it is not a subclass of QWidget there is no such setting.

    Perhaps I am expressing it in the wrong way. More clearly step by step:
    1) Left mouse button is pressed anywhere on the scene and hold pressed
    2) Now the cursor goes through my QGraphicsItem object
    3) Result: None of mouse events are detected

    As Wysota said the scene is the mouse grabber; so that is an expected behaviour. But i am still curious if there is an alternative method to achieve my goal

  11. #10
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to detect hover events when mouse button is pressed

    I am dealing with QGraphicsItem. Since it is not a subclass of QWidget there is no such setting.
    But you don't want to intercept events on the GraphicsItem; you want to intercept them within the GraphicsView. Which is a ScrollArea.

    In any case, more primitive tracking is the only way to do what you're asking. Once things have progressed to the level of hovering, no meaningful such events are going to occur over your GraphicsItem. You have to take responsibility for implementing such handling at a lower level, as noted above.

  12. The following user says thank you to SixDegrees for this useful post:

    yagabey (21st May 2011)

  13. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to detect hover events when mouse button is pressed

    Quote Originally Posted by yagabey View Post
    I am dealing with QGraphicsItem. Since it is not a subclass of QWidget there is no such setting.

    Perhaps I am expressing it in the wrong way. More clearly step by step:
    1) Left mouse button is pressed anywhere on the scene and hold pressed
    2) Now the cursor goes through my QGraphicsItem object
    3) Result: None of mouse events are detected

    As Wysota said the scene is the mouse grabber; so that is an expected behaviour. But i am still curious if there is an alternative method to achieve my goal
    Could you say what you need this functionality for? Maybe there are better ways to achieve it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  14. #12
    Join Date
    Jul 2013
    Posts
    15
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to detect hover events when mouse button is pressed

    I'm sorry to up the topic, but I've got the exact same problem.

    I want to create a Map Editor. I use QGraphics Scene and QGraphics View to draw the map, and I use QGraphicsItem for every tiles (32x32 pixels). I have two areas : One is the tileset where I can select the tile I want to use, and the other represents the map where I can use my selected tile and put it where I want on the map.

    My problem is : If I click a tile and then I move my mouse to another tile, it doesn't draw the selected tiles on both of them, but only on the one I clicked first.
    Also: I use the hoverEvent to draw cursor on the tiles. When I move my mouse on a tile, it shows that I want to select THIS tile. But if I click it and then I move, the cursor doesn't follow the mouse anymore.

    I don't know if my problem is clear but I would apreciate very much if you could help me !
    (Sorry for my bad english).

  15. #13
    Join Date
    Apr 2016
    Posts
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Windows Android

    Default Re: How to detect hover events when mouse button is pressed

    Quote Originally Posted by wysota View Post
    Could you say what you need this functionality for? Maybe there are better ways to achieve it.
    I still got is problem currently, and how you finally deal with it ?

    Quote Originally Posted by Grade View Post
    I'm sorry to up the topic, but I've got the exact same problem.

    I want to create a Map Editor. I use QGraphics Scene and QGraphics View to draw the map, and I use QGraphicsItem for every tiles (32x32 pixels). I have two areas : One is the tileset where I can select the tile I want to use, and the other represents the map where I can use my selected tile and put it where I want on the map.

    My problem is : If I click a tile and then I move my mouse to another tile, it doesn't draw the selected tiles on both of them, but only on the one I clicked first.
    Also: I use the hoverEvent to draw cursor on the tiles. When I move my mouse on a tile, it shows that I want to select THIS tile. But if I click it and then I move, the cursor doesn't follow the mouse anymore.

    I don't know if my problem is clear but I would apreciate very much if you could help me !
    (Sorry for my bad english).
    I still got is problem currently, and how you finally deal with it ?
    thanks.

Similar Threads

  1. Replies: 6
    Last Post: 4th October 2010, 04:19
  2. Replies: 0
    Last Post: 26th June 2010, 01:40
  3. Replies: 2
    Last Post: 13th May 2009, 20:01
  4. problem about mouse button events
    By vql in forum Qt Programming
    Replies: 1
    Last Post: 29th April 2008, 11:14
  5. QPushButton:: Handle right mouse button events. Easyway?
    By Harvey West in forum Qt Programming
    Replies: 6
    Last Post: 28th February 2007, 17:56

Tags for this Thread

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.