def autoscale(self, flag): self._autoscale = bool(flag) if self._autoscale: self.fitInView() else: self.setTransform(QtGui.QTransform()) self.update()
def openfile(self): self.scene.clear() self.graphicsview.setTransform(QtGui.QTransform()) filename = QtWidgets.QFileDialog.getOpenFileName() if filename: pixmap = QtGui.QPixmap(filename) item = self.scene.addPixmap(pixmap) self.scene.setSceneRect(item.boundingRect())
def _setupViewActions(self): style = self.style() actions = QtWidgets.QActionGroup(self) icon = style.standardIcon(QtWidgets.QStyle.SP_DialogResetButton) QtWidgets.QAction(icon, self.tr('Reset'), actions, objectName='resetAction', statusTip=self.tr('Reset'), triggered=self.onReset) QtWidgets.QAction(actions).setSeparator(True) icon = QtGui.QIcon( ':/trolltech/dialogs/qprintpreviewdialog/images/zoom-in-32.png') QtWidgets.QAction(icon, self.tr('Zoom In'), actions, objectName='zoomInAction', statusTip=self.tr('Zoom In'), shortcut=self.tr('Ctrl++'), triggered=lambda: self.graphicsview.scale(1.2, 1.2)) icon = QtGui.QIcon( ':/trolltech/dialogs/qprintpreviewdialog/images/zoom-out-32.png') QtWidgets.QAction( icon, self.tr('Zoom Out'), actions, objectName='zoomOutAction', statusTip=self.tr('Zoom Out'), shortcut=self.tr('Ctrl+-'), triggered=lambda: self.graphicsview.scale(1 / 1.2, 1 / 1.2)) icon = QtGui.QIcon( ':/trolltech/dialogs/qprintpreviewdialog/images/page-setup-24.png') QtWidgets.QAction(icon, self.tr('Zoom 1:1'), actions, objectName='zoomResetAction', statusTip=self.tr('Zoom 1:1'), triggered=lambda: self.graphicsview.setTransform( QtGui.QTransform(1, 0, 0, -1, 0, 0))) icon = QtGui.QIcon( ':/trolltech/dialogs/qprintpreviewdialog/images/fit-page-32.png') QtWidgets.QAction( icon, self.tr('Zoom Fit'), actions, objectName='zoomFitAction', statusTip=self.tr('Zoom Fit'), #checkable=True, triggered=lambda: self.graphicsview.fitInView( self.graphicsview.sceneRect(), QtCore.Qt.KeepAspectRatio)) return actions
def setWorldmapItem(self, resolution='low'): scene = self.graphicsview.scene() if self.worldmapitem is not None: scene.removeItem(self.worldmapitem) #~ imgfile = qt4support.geticonfile('world_2160x1080.jpg', __name__) imgfile = qtsupport.geticonfile('world_4320x2160.jpg', __name__) #~ imgfile = qt4support.geticonfile('world_5400x2700.jpg', __name__) worldmap = QtGui.QPixmap(imgfile) worldmapitem = scene.addPixmap(worldmap) worldmapitem.setTransformationMode(QtCore.Qt.SmoothTransformation) # @NOTE: reverse the y axis worldmapitem.setTransform( QtGui.QTransform(360. / worldmap.width(), 0, 0, -180. / worldmap.height(), -180, 90)) self.worldmapitem = worldmapitem
def reset(self): self.scene.clear() self.scene.setSceneRect(0, 0, 800, 600) self.graphicsview.setTransform(QtGui.QTransform())
def zoom100(self): view = self.currentview() if view: view.setTransform(QtGui.QTransform())