python调整屏幕缩放比例_如何将QGraphicsView缩放比例恢复到100%,即程序启动时的缩放比例?...

fromPyQt4importQtGui,QtCoreclassMyFrame(QtGui.QGraphicsView):"""

Python PyQt: How can I move my widgets on the window with mouse?

https://stackoverflow.com/questions/12213391/python-pyqt-how-can-i-move-my-widgets-on-the-window-with-mouse

"""def__init__(self,parent=None):super(MyFrame,self).__init__(parent)scene=QtGui.QGraphicsScene()self.setScene(scene)self.resize(400,340)# http://pyqt.sourceforge.net/Docs/PyQt4/qpen.htmlpencil=QtGui.QPen(QtCore.Qt.black,1)pencil.setStyle(QtCore.Qt.SolidLine)scene.addLine(QtCore.QLineF(0,-50,0,50),pencil)scene.addLine(QtCore.QLineF(-50,0,50,0),pencil)fitInViewButton=QtGui.QPushButton('Fit In View',self)fitInViewButton.clicked.connect(self.handleFitInView)scene.addWidget(fitInViewButton)defhandleFitInView(self):# Auto scale a QGraphicsView# http://www.qtcentre.org/threads/42917-Auto-scale-a-QGraphicsViewself.ensureVisible(self.scene().itemsBoundingRect())self.fitInView(self.scene().itemsBoundingRect(),QtCore.Qt.KeepAspectRatio)defwheelEvent(self,event):"""

PyQT4 WheelEvent? how to detect if the wheel have been use?

https://stackoverflow.com/questions/9475772/pyqt4-wheelevent-how-to-detect-if-the-wheel-have-been-use

QGraphicsView Zooming in and out under mouse position using mouse wheel

https://stackoverflow.com/questions/19113532/qgraphicsview-zooming-in-and-out-under-mouse-position-using-mouse-wheel

"""# Zoom FactorzoomInFactor=1.1zoomOutFactor=1/zoomInFactor# Set Anchorsself.setTransformationAnchor(QtGui.QGraphicsView.NoAnchor)self.setResizeAnchor(QtGui.QGraphicsView.NoAnchor)# Save the scene posoldPos=self.mapToScene(event.pos())# Zoomifevent.delta()>0:zoomFactor=zoomInFactorelse:zoomFactor=zoomOutFactor

self.scale(zoomFactor,zoomFactor)# Get the new positionnewPos=self.mapToScene(event.pos())# Move scene to old positiondelta=newPos-oldPos

self.translate(delta.x(),delta.y())if(__name__=='__main__'):app=QtGui.QApplication([])f=MyFrame()f.show()app.exec_()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值