我正在使用标准的 QGraphicsView 和 QGraphicsScene,但是为了能够在 ImagePixmapItem 上使用鼠标事件,我将 QGraphicsPixmapItem 子类化为我自己的 ImagePixmapItem。
我需要做什么才能捕捉到这些事件?我已经覆盖了几个这样的函数:
void ImagePixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event){
qDebug("hello");
}
void ImagePixmapItem::wheelEvent ( QGraphicsSceneWheelEvent * event ){
qDebug("Print this line if catch a wheelEvent");//this is never printing
}
但是,这些 qDebug 语句都不会打印到控制台。我是否需要更改有关我的场景或图形视图的任何其他内容?在 ImagePixmapItem 的构造函数中,我确实添加了一些东西:
setAcceptHoverEvents(true);
setFlag(QGraphicsItem::ItemIsSelectable,true);
但它没有做任何好事。