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
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
You have to ask for the hover events to be sent by setting an appropriate flag on your item.
I couldnt find any related flag. Is there one? In the documentation it is said that:
I couldnt find a way to deliver the event when there is a mouse grabber.(mouse pressed)Hover events are delivered when there is no current mouse grabber item
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.
When the button is pressed, you get mouse events -- mousePressEvent, mouseMoveEvent and mouseReleaseEvent.
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.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.
yagabey (21st May 2011)
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.
I am dealing with QGraphicsItem. Since it is not a subclass of QWidget there is no such setting.If you want to perform mouse TRACKING, there is a setting for that in the Widget class
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
But you don't want to intercept events on the GraphicsItem; you want to intercept them within the GraphicsView. Which is a ScrollArea.I am dealing with QGraphicsItem. Since it is not a subclass of QWidget there is no such setting.
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.
yagabey (21st May 2011)
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).
Bookmarks