def __init__(self, scene):
horizontalScrollBar = self.horizontalScrollBar()
horizontalScrollBar.hide()
verticalScrollBar = self.verticalScrollBar()
verticalScrollBar.hide()
def __init__(self):
def set_image(self, pixmap, width, height)
image
= pixmap.
scaled(QtCore.
QSize(x,y
),QtCore.
Qt.
KeepAspectRatio,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)
self.canvas_view.show()
class CanvasView(QtGui.QGraphicsView):
def __init__(self, scene):
QtGui.QGraphicsView.__init__(self, scene)
horizontalScrollBar = self.horizontalScrollBar()
horizontalScrollBar.hide()
verticalScrollBar = self.verticalScrollBar()
verticalScrollBar.hide()
class CanvasScene(QtGui.QGraphicsScene):
def __init__(self):
QtGui.QGraphicsScene.__init__(self)
def set_image(self, pixmap, width, height)
image = pixmap.scaled(QtCore.QSize(x,y),QtCore.Qt.KeepAspectRatio,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)
self.canvas_view.show()
To copy to clipboard, switch view to plain text mode
Bookmarks