Capturing hover events for a QGraphicsRectItem
-
Did
setAcceptHoverEvents(true)
in the constructor and implemented,void hoverEnterEvent(QGraphicsSceneHoverEvent *event); void hoverMoveEvent(QGraphicsSceneHoverEvent *event); void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
But still the
QGraphicsRectItem
is not capturing the hover events? Am I missing something?BoundingRectItem::BoundingRectItem() { setFlag(QGraphicsItem::ItemIsMovable); _transformMode = false; _width = 0; _height = 0; setAcceptHoverEvents(true); } ... ... void BoundingRectItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { event->accept(); qDebug() << "yeah"; } void BoundingRectItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { event->accept(); qDebug() << "yeah"; } void BoundingRectItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { event->accept(); qDebug() << "yeah"; }
Here is the complete source and the header file for the implemented
QGraphicsRectItem
-
Did
setAcceptHoverEvents(true)
in the constructor and implemented,void hoverEnterEvent(QGraphicsSceneHoverEvent *event); void hoverMoveEvent(QGraphicsSceneHoverEvent *event); void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
But still the
QGraphicsRectItem
is not capturing the hover events? Am I missing something?BoundingRectItem::BoundingRectItem() { setFlag(QGraphicsItem::ItemIsMovable); _transformMode = false; _width = 0; _height = 0; setAcceptHoverEvents(true); } ... ... void BoundingRectItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { event->accept(); qDebug() << "yeah"; } void BoundingRectItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { event->accept(); qDebug() << "yeah"; } void BoundingRectItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { event->accept(); qDebug() << "yeah"; }
Here is the complete source and the header file for the implemented
QGraphicsRectItem
@hellozee
you need to make sure that alsoboundingRect()shape()
returns a plausible value for your custom item
So either you reimplement this method yourself or (suggested) you need to set the rect also to the base class (QGraphicsRectItem::setRect()
)