View Full Version : QGraphicsView on Linux vs. Windows

17th September 2008, 18:24
I am using a QGraphicsView from Qt 4.3.3 as well as PyQt4 and adding a PixmapItem to the scene and then centering it in the view. In windows it shows up correctly in the view, but in linux it's shifted to the left side of the frame and the pixmap is cut off?

Does anyone know why the QGraphicsView/Scene is displayed differently in both windows and linux and what I can do to make it appear properly in Linux.


class CanvasView(QtGui.QGraphicsView):

def __init__(self, scene):
QtGui.QGraphicsView.__init__(self, scene)

horizontalScrollBar = self.horizontalScrollBar()

verticalScrollBar = self.verticalScrollBar()

class CanvasScene(QtGui.QGraphicsScene):

def __init__(self):

def set_image(self, pixmap, width, height)
image = pixmap.scaled(QtCore.QSize(x,y),QtCore.Qt.KeepAspe ctRatio,QtCore.Qt.SmoothTransformation)
pixmap_item = self.addPixmap(image)

# Code is added here to get the center point
# and the pixmap item is moved to the center
pixmap_item.setPos(center_x, center_y)

self.canvas = CanvasScene(self)
self.canvas.setSceneRect(0,0, 478, 250)

self.canvas_view = CanvasView(self.canvas)
self.canvas_view.setParent(self) # parent is set to a QFrame
self.canvas.set_image(pixmap, 300, 250)

17th September 2008, 22:50
I figured it out, I had to call resize on the viewport. I'm not really sure why I needed to do that, but that seems to work.