QGraphicsItem doesn't receive mouse hover events

前端 未结 2 698
温柔的废话
温柔的废话 2021-01-17 08:18

I have a class derived from QGraphicsView, which contains QGraphicsItem-derived elements. I want these elements to change color whenever the mouse

相关标签:
2条回答
  • 2021-01-17 08:39

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

    0 讨论(0)
  • 2021-01-17 08:39

    In my case, hover events wouldn't work if I overrode mouseMoveEvent in my implementation of the QGraphicsView class. I fixed this by adding a call to

    QGraphicsView::mouseMoveEvent(event);
    

    which propagated the event to the parent, which in turn sent it out to all the scene items.

    0 讨论(0)
提交回复
热议问题