如何安装和处理Qt graphicsview的事件过滤器

时间:2010-07-22 14:05:29

标签: qt events event-handling qt4 symbian

我有一个graphicsview和一个graphicsscen,但我不知道如何安装和处理事件过滤器来获取键盘事件。任何人都可以帮我吗?

提前致谢。

2 个答案:

答案 0 :(得分:0)

如果您已创建自定义QGraphicsScene类,则可以覆盖QWidget" QWidget :: keyPressEvent()"和" QWidget :: keyReleaseEvent()"方法

class MyGraphicsScene : QGraphicsScene
{
    void keyPressEvent(QKeyEvent *event);
}

//in cpp
void MyGraphicsScene::keyPressEvent(QKeyEvent *event)
{
    // do sth with event
}

如果您只使用QGraphicsScene,则可以使用父的keyPressEvent。是否必须提供更多详细信息

答案 1 :(得分:0)

您有两种选择:

1)基于QGraphicsView创建自己的类并覆盖keyPressEvent()。只有你要改变很多其他事情才有意义。

2)安装事件过滤器,使用installEventFilter(..)方法并传递过滤器对象,它将接收您可能需要的所有内容