QGraphicsItem doesn't receive mouse hover events
Posted
by Jen
on Stack Overflow
See other posts from Stack Overflow
or by Jen
Published on 2010-05-30T21:23:15Z
Indexed on
2010/05/30
21:32 UTC
Read the original article
Hit count: 247
I have a class derived from QGraphicsView
, which contains QGraphicsItem
-derived elements. I want these elements to change color whenever the mouse cursor hovers over them, so I implemented hoverEnterEvent
(and hoverLeaveEvent
):
void MyGraphicsItem::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
{
update (boundingRect());
}
However, this event handler code is never executed. I've explicitly enabled mouse tracking:
MyGraphicsView::MyGraphicsView(MainView *parent) :
QGraphicsView(parent)
{
setMouseTracking(true);
viewport()->setMouseTracking(true);
...
}
Still, no luck. What am I doing wrong?
© Stack Overflow or respective owner