0

我正在使用标准的 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);

但它没有做任何好事。

4

1 回答 1

0

您可以使用事件过滤器。

http://cartan.cas.suffolk.edu/qtdocs/eventsandfilters.html

我还要为您的原始示例添加这一点,请务必在相关小部件上启用鼠标跟踪。

于 2011-01-21T19:52:40.147 回答