如何在QGraphicsView上添加“on click event”

时间:2012-06-22 11:40:06

标签: qt

我在Designer中添加了一个QGraphicsView到我的ui表单。现在我想在这个小部件上添加一个“on click event”。

1 个答案:

答案 0 :(得分:1)

您是否可以继承QGraphicsView?如果是这样,你可以用这样的东西轻松处理案件:

MyQGraphicsView.h

class MyQGraphicsView : public QGraphicsView
{
    void enterEvent(QEvent *event);
    void leaveEvent(QEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void wheelEvent(QWheelEvent *event);
}

MyQGraphicsView.cpp

void MyQGraphicsView::mouseMoveEvent(QMouseEvent *event)
{
    // Do what you want
}

//Do the same with all the events.