QT how to install a scene event filter for the graphic element?

void QGraphicsItem::installSceneEventFilter(QGraphicsItem *filterItem)

class LabCrossEvent : public QGraphicsObject
{
    Q_OBJECT
public:
    LabCrossEvent() {}
    virtual ~LabCrossEvent() {}

    virtual QRectF boundingRect() const
    {
        return QRectF();
    }

    virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = Q_NULLPTR)
    {

    }
signals:
    void hover();
public slots:
protected:
    bool LabCrossEvent::sceneEventFilter(QGraphicsItem * watched, QEvent * event)
    {
        qDebug() << "||" << event->type();
        if(event->type() == QEvent::GraphicsSceneMove)
        {
            emit hover(); // signal that the item was moved
        }
        //return  sceneEventFilter(watched,event);
        return false; // pass the event to the original target item
    }

};


        QGraphicsItem* dL_Item = this->addRect(-22,-std::abs(high_dL),44,height_dL,QPen(QColor("#239B56")));
        
        //The installed scene filter must be added to the scene, otherwise the event filter is invalid.This-> addItem (& _labCrossEvent);/ / install a scene event for rectangle primitives.FilterDL_Item-> installSceneEventFilter (& _labCrossEvent);

Leave a Reply

Your email address will not be published. Required fields are marked *