开发者

intercept mouse events when creating a custom QGraphicsItem

I am using a standard QGraphicsView and QGraphicsScene, but I have subclassed a QGraphicsPixmapItem to my own ImagePixmapItem for the purposes of being able to use the mouse events on the ImagePixmapItem.

What do I need to do to be able to capture those events? I have overridden a couple of functions like so:

   void ImagePixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event){

       qDebug("hello");

   }

void ImagePixmapItem::wheelEvent ( QGraphicsSceneWheelEvent * event ){
    qDebug("Print this line if catch a wheelEvent");//this is never printing

}

However, neither of those qDebug statements ever print to console. Do I need to change anything else about my scene or graphicsview? In the constructor for the ImagePixmapItem, i did add a couple of things:

setAcceptHoverEvents(true);
setFlag(QGraphicsItem::ItemIsSelectable,true);

Bu开发者_如何学Got it has done no good.


You can use event filters.

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

I would also add that for your original example, be sure to enable mouse tracking on the widgets in question.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜