标题:关于QGraphicsView上获取QGraphicsScene坐标的问题
作者:eric584930
日期:2013-11-21 14:32
内容:
一、通过QGraphicsView::mousePressEvent(QMouseEvent *event )获取鼠标的坐标event ->pos(),然后利用mapToScene(event ->pos)取得鼠标在QGraphicsScene上的坐标,在没有对view进行任何缩放的时,得到的坐标是对的,但是如果对view进行缩放后得到的就不对。
二、通过QGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *event)获取鼠标在QGraphicsScene的坐标event->scenePos(),不管有没有缩放都是对的。
问题:请问【情况一】的问题出在哪儿?我现在需要通过【一】来获得对应scene上的坐标。
#1 [彩阳 11-21 21:17]
可能是缩放了,像素和scene不能一一对应吧。如果这样,我会选择第二种方法。
#2 [lclflash 11-21 22:06]
你需要先把view的当前矩阵求逆,然后再 maptoscene就可以了
#3 [ruanjian 02-19 12:42]
我想问一下,我的鼠标事件为什么在QGraphicsView空白框里面可以响应,而在QGraphicsView中加入QGraphicsScene之后就无响应了呢?