PDA

View Full Version : How to detect hover events when mouse button is pressed



yagabey
20th May 2011, 16:34
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

wysota
20th May 2011, 22:48
You have to ask for the hover events to be sent by setting an appropriate flag on your item.

yagabey
21st May 2011, 00:19
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)

wysota
21st May 2011, 00:20
QGraphicsItem::setAcceptHoverEvents()

yagabey
21st May 2011, 12:26
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.

wysota
21st May 2011, 13:08
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.

yagabey
21st May 2011, 15:49
Ok thanks. So it means that there is no way to detect hover events if some other item is the grabber item..Right?

SixDegrees
21st May 2011, 17:33
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.

yagabey
21st May 2011, 19:20
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:confused:

SixDegrees
21st May 2011, 20:13
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.

wysota
22nd May 2011, 18:28
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:confused:

Could you say what you need this functionality for? Maybe there are better ways to achieve it.

Grade
13th July 2013, 19:11
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).

suxiaojian1987@gmail.com
26th April 2016, 10:26
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 ?


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.