I wrote the following example code to illustrate what it is that's confusing me:
from PyQt4 import QtGui, QtCore
import sys
class Spam(QtGui.QWidget):
def __init__(self):
super(Spam, self).__init__()
self.setGeometry(50, 50, 400, 400)
self.scene = QtGui.QGraphicsScene(self)
self.view = QtGui.QGraphicsView(self.scene, self)
def resizeEvent(self, event):
self.view.setFixedSize(event.size())
self.view.setSceneRect(-100, -100, 200, 200)
rect = self.view.sceneRect()
print(rect.x(), rect.y(), rect.width(), rect.height())
print(self.view.mapFromScene(-100, -100))
def run():
app = QtGui.QApplication(sys.argv)
GUI = Spam()
GUI.show()
sys.exit(app.exec_())
run()
What this does is it makes a window with a QGraphicsView linking to an empty QGraphicsScene, and responding to a resize event by changing the size of the view and setting the QGraphicsView's sceneRect to (-100, -100, 200, 200). I believe the point (-100, -100) in the scene should correspond to (0, 0) in the view, because it is the upper left corner of the sceneRect. However, when I map (-100, -100) from the scene, I get (99, 99) and I don't know why. This is the output from the above program:
>>>
-100.0 -100.0 200.0 200.0
PyQt4.QtCore.QPoint(99, 99)
I printed the dimensions of the sceneRect immediately before the point to insure that it didn't change from what I set it to for any reason. I'm sure I'm just missing something obvious, but I've looked at it for a while now and I don't understand what's going on.