求救:installSceneEventFilter与sceneEventFilter捕获消息的问题!sceneEventFilter断点么有被激活!



  • 各位大侠:
    请教一个问题,我在sceneEventFilter中设置了断点没有被激活
    使用方法如下:
    class A :public QGraphicsObject
    {
    A()
    {
    QLineF line(.....);
    QGraphicsLineItem* lineSeg = new QGraphicsLineItem(line);

    lineSeg->installSceneEventFilter(this);

                   registerGraphicsItemInScene(lineSeg);
    

    }
    bool sceneEventFilter(QGraphicsItem * watched, QEvent * event)
    {
    QMessageBox msgBox;
    msgBox.setText(_blockItem->name());
    msgBox.exec();
    switch(event->type())
    {
    case QEvent::MouseButtonDblClick:
    return true;
    case QEvent::MouseButtonPress:
    return true;
    case QEvent::MouseButtonRelease:
    return true;
    }

    return QGraphicsItem::sceneEventFilter(watched, event);
    }
    }

    main()
    {
    A a;
    registerGraphicsItemInScene(&a);
    ........

    }

    然后,在测试的过程中,sceneEventFilter根本没有被调用。请问这是什么情况,怎么样能解决啊?



  • class A :public QGraphicsObject
    {
    A()
    { QLineF line(…..);
    QGraphicsLineItem* lineSeg = new QGraphicsLineItem(line);
    lineSeg->installSceneEventFilter(this);
    registerGraphicsItemInScene(lineSeg);
    }
    bool sceneEventFilter(QGraphicsItem * watched, QEvent * event)
    {
    QMessageBox msgBox;
    msgBox.setText(_blockItem->name());
    msgBox.exec();
    switch(event->type())
    {
    case QEvent::MouseButtonDblClick: return true;
    case QEvent::MouseButtonPress: return true;
    case QEvent::MouseButtonRelease: return true; }
    return QGraphicsItem::sceneEventFilter(watched, event); }
    }
    main()
    {
    A a;
    registerGraphicsItemInScene(&a);
    ……..

    }


Log in to reply
 

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