使Controll鼠标放大QGraphicsView

时间:2016-01-26 13:35:50

标签: python qt pyqt qgraphicsview

我有bindData(){ this.invArr = this.invLookUpSvc.getPortalInvByProdNbrSum().query({ rtbProductNbr: this.productNumber }, function (data) { if (angular.isDefined(data)) { this.invArr = data; //this.invArr not found console.log(this.maxSize); //this.MaxSize not found. } }); } 可以显示图像,放大和缩小。这是代码:

QGraphicsView

我想要做的是限制放大或缩小。图像大小缩放class MyQGraphicsView(QtGui.QGraphicsView): def __init__ (self, parent=None): super(MyQGraphicsView, self).__init__ (parent) def wheelEvent(self, event): # Zoom Factor zoomInFactor = 1.25 zoomOutFactor = 1 / zoomInFactor # Set Anchors self.setTransformationAnchor(QtGui.QGraphicsView.NoAnchor) self.setResizeAnchor(QtGui.QGraphicsView.NoAnchor) # Save the scene pos oldPos = self.mapToScene(event.pos()) # Zoom if event.delta() > 0: zoomFactor = zoomInFactor else: zoomFactor = zoomOutFactor self.scale(zoomFactor, zoomFactor) # Get the new position newPos = self.mapToScene(event.pos()) # Move scene to old position delta = newPos - oldPos self.translate(delta.x(), delta.y()) 大小,如下所示:

qgraphicsview

如您所见,图片尺寸等于 scene = QtGui.QGraphicsScene() pixmap = QtGui.QPixmap('pic.jpeg') w = self.graphicsView.width() h = self.graphicsView.height() scene.addPixmap(pixmap.scaled(QtCore.QSize(w,h))) self.graphicsView.setScene(scene) 尺寸。在这个位置,我不希望用户缩小图像。仅当用户放大图像时,才可以缩小,但直到图像大小等于qgraphicsview大小。我没控制住这个。你能建议我一个方法吗?

0 个答案:

没有答案