Is There a way to get Mouse Position in a sceneEventFilter?[Solved]



  • Hello,

    I would listen in a QGraphicsItem mouse Events from other QGraphicsItems like this:

    @

    class item1 : public QGraphicsItem;
    {
    ......
    }

    class item2 : public QGraphicsItem;
    {
    bool sceneEventFilter(QGraphicsItem* watched, QEvent* event)
    {

        if (event->type() == QEvent::GraphicsSceneMouseMove) {
            QMouseEvent* mouse = static_cast<QMouseEvent*>(event);
            qDebug() << mouse->pos();
        }
    }
    

    }

    QGraphicsItem* item1 = new QGraphicsItem;
    QGraphicsItem* Item2 = new QGraphicsItem;

    item1->installSceneEventFilter(item2);

    @

    But output is definitly not correct, something like QPointF(141, 1.08089e+09).
    The Items are in the same Scene.

    Is there a way to get mouse coords in a sceneEventFilter?

    Thanks in advance, wesu



  • You should probably cast to QGraphicsSceneMouseEvent instead of QMouseEvent



  • Oh yeah i should... Thx you



  • Please mark the post title as [Solved]. Thanks


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.