【发布时间】:2011-01-21 18:54:52
【问题描述】:
我使用的是标准的 QGraphicsView 和 QGraphicsScene,但我已将 QGraphicsPixmapItem 子类化为我自己的 ImagePixmapItem,以便能够在 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);
但它没有做任何好事。
【问题讨论】:
-
您能告诉我们您是如何将这些项目添加到 {{QGraphicsScene}} 的吗?
标签: c++ qt qgraphicsview