PDA

View Full Version : hoverover for boundingrect qgraphicsitem



rogerholmes
11th January 2010, 01:20
is there a way to check if mouse is over (within) the boundingrect for a qgraphicsitem. (akin to hoverover)

kichi
11th January 2010, 14:17
is there a way to check if mouse is over (within) the boundingrect for a qgraphicsitem. (akin to hoverover)

If you write the custom item class, you can handle hoverEnterEvent()、hoverLeaveEvent()、hoverMoveEvent ().
By default, items do not accept hover events. so it is necessary to call setAcceptHoverEvents(true).

I'm sorry in poor English.

rogerholmes
11th January 2010, 15:34
Kichi,

Thank You for you response.

I am using that. I need a similar functionally for boundingrect, hover events only fire when the mouse is over the actual image, i want to have a method fire when mouse is over the boundingrect of the image.

wysota
11th January 2010, 19:49
is there a way to check if mouse is over (within) the boundingrect for a qgraphicsitem. (akin to hoverover)

It really depends on the context. The simplest way would be to use this:


QPointF pos = ...
bool inside = item->boundingRect().contains(pos);
If you can have the position of the cursor in item coordinates (i.e. in item events containing the cursor position).

If you have the position of the cursor relative to the scene or the view then you can use the family of mapTo* or mapFrom* to get to local coordinates and use the code above.

rogerholmes
11th January 2010, 21:47
Thank You Wysota,

I will try that.