from PyQt5.Qt import *
class Window(QWidget):
def __init__(self,parent=None):
super().__init__(parent)
self.parent=parent
def paintEvent(self, event) -> None:
painter=QPainter(self)
painter.fillRect(50,50,self.width(),self.height(),Qt.gray)
painter.translate(0,self.height())
painter.scale(1,-1)
for i in range(500):
painter.drawLine(i,i,i+1,i+1)
if __name__ == '__main__':
import sys
app=QApplication(sys.argv)
win=Window()
win.show()
sys.exit(app.exec_())
利用translate(x,y)移动原点坐标位置。scale(a,b)可以缩放坐标或改变坐标方向。例如painter.scale(3,3)显示尺寸放大3倍,painter.scale(1,-1)即将y轴方向取反。