我有一个派生自QGraphicsView
的类,其中包含QGraphicsItem
派生元素。当鼠标光标悬停在这些元素上时,我希望它们能够改变颜色,因此我实现了hoverEnterEvent
(和hoverLeaveEvent
):
void MyGraphicsItem::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
{
update (boundingRect());
}
然而,这个事件处理程序代码从未被执行。我已经明确启用了鼠标跟踪:
MyGraphicsView::MyGraphicsView(MainView *parent) :
QGraphicsView(parent)
{
setMouseTracking(true);
viewport()->setMouseTracking(true);
...
}
仍然没有运气。我做错了什么?
QGraphicsView
中删除mouseMoveEvent
实现也是解决它所必需的。现在我已经解决了这个问题,只要我找出一种不会吞噬QEvent
的方法,我可能可以重新添加mouseMoveEvent
。 - Cory Klein