加载图片
class SeisPro(QtWidgets.QMainWindow, Ui_SeismicProgramme):
def __init__(self, parent=None):
super(SeisPro, self).__init__(parent)
# 设置窗体
self.setupUi(self)
# 输入框默认值设置
self.time_txt.setPlainText("0")
self.velocity_txt.setPlainText("0")
self.distance_txt.setPlainText("0")
# 绘图控件,创建一个QGraphicsScene
self.velocity_view.setScene(QGraphicsScene())
# 按钮
self.oky_btn.clicked.connect(self.oky_btn_func)
self.cancel_btn.clicked.connect(self.cancel_btn_fnc)
def oky_btn_func(self):
self.distance_txt.setPlainText("1")
self.add_velocitypic()
self.add_distancepic()
# self.plt_distancepic()
def add_velocitypic(self):
frame = QImage("person.jpg")
pix = QPixmap.fromImage(frame)
pix = pix.scaled(200, 260) # 调整图片大小為 200x260
item = QGraphicsPixmapItem(pix)
scene = QGraphicsScene()
# QGraphicsScene 相對位置 (20, 20) 和大小 200x260
scene.setSceneRect(0, 0, 200, 260)
scene.addItem(item)
self.velocity_view.setScene(scene)
绘制函数图
def fnc(self):
# 1. 创建场景
scene = QGraphicsScene()
# 2. 创建元素
originX,originY = 40,60 #坐标基点
pen = QtGui.QPen(QtGui.QColor(QtCore.Qt.GlobalColor.red))
# rectF = QtCore.QRectF(originX+300-8, originY-25, 20, 50)
# elpItem = scene.addEllipse(rectF, pen)
# 3. 绘制曲线
pen.setColor(QtGui.QColor(Qt.GlobalColor.blue))
path = QtGui.QPainterPath()
path.moveTo(originX,originY)
path.cubicTo(originX+100, originY-150, originX+200, originY+150,originX+300,originY)
myGradient = QtGui.QLinearGradient()
itemPath = scene.addPath(path,pen,myGradient)
# 3. 加载内容到场景中
scene.addItem(itemPath)
# # 4. 将场景添加至视图
self.distance_view.setScene(scene)