[SOLVED] hover{Enter/Move/Leave}Event() events called only when QGraphicsItems is clicked
-
Hi all,
I think the topic title explains most of the problem. I am trying to catch the hoverEnterEvent() on a QGraphicsItem using a pretty simple event handler:
@void NodeItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event)qDebug() << "Mouse entering NodeItem";
}@
However, the message appears only if I click the Item. Same happens with hoverMove and hoverLeave events. Why is that?
Edit: I did set the setAcceptHoverEvents(true) in my constructor.
-
The only thing that worked for me was setting the protected function to virtual:
@protected:
//hover events
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);@ -
The only other thing I can think of would be setting a flag. For my objects I have:
@
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemSendsScenePositionChanges | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemSendsGeometryChanges);
setAcceptHoverEvents(true);
@But I wouldn't think that any of those enable hovering.
-
are you sure you are not filtering the events to the graphics-view's viewport?
-
Yes. Qt uses the boundingRect() function to pass events to objects, based on their location.
-
Hmm. I would say look at the colliding mice example (Qt\Version\examples\graphicsview\collidingmice), and see if you can implement something close to that. The colliding mice example doesn't currently have hover events, but you could implement them.
-
Tried it... and it works perfectly for the mice! I am clueless about what I am doing wrong here.
Could the fact that my NodeItem subclasses the QGraphicsProxyWidget class instead of QGraphicsItem cause a problem? The NodeItem is also composed of a few child QWidgets and QGraphicsItem.
EDIT: I also subclass the QGraphicsView and QGraphicsScene classes to implement custom behavior. Should I do anything with the event()/eventFilter() functions?
MORE EDITS: Don't think the event()/eventFilter() functions have anything to do with it, as I just ran some experiments on the more complex Diagramscene example and it works! :'(