Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QGraphicsItem doesn't receive mouse hover events

Tags:

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?

like image 604
Tony the Pony Avatar asked May 30 '10 21:05

Tony the Pony


1 Answers

Fixed it. I need to use setAcceptHoverEvents(true) in the constructor of my QGraphicsItem-derived class.

like image 61
Tony the Pony Avatar answered Oct 02 '22 11:10

Tony the Pony