標準の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);
しかし、それは役に立たなかった。