我在Designer中添加了一个QGraphicsView到我的ui表单。现在我想在这个小部件上添加一个“on click event”。
答案 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.