QGraphicsItem获取不到鼠标事件

来源:互联网 发布:2017淘宝贷款15万骗局 编辑:程序博客网 时间:2024/06/03 19:25

鼠标事件一直停留在QGraphicsScene中,没有传到QGraphicsItem中去
有两点需要注意:
1.QGraphicsItem的大小,也就是boundingRect必须设置正确
2.在item的构造函数中添加
this->setAcceptedMouseButtons(Qt::LeftButton);
setFlag(QGraphicsItem::ItemIsSelectable);//必须加上这句,否则item无法获取到鼠标事件

原创粉丝点击