pyqt如何在已设置ui窗口里使用qpainter绘图?

pyqt如何在已设置ui窗口里使用qpainter绘图?

ui窗口是用qtdesigner做的,通过pyuic转换成了.py文件,如何在.py中使用Qpainter进行绘图?
代码如下
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtGui import QPainter, QPen

class Ui_Form(object):

def setupUi(self, Form):

Form.setObjectName("Form")

Form.resize(400, 300)

self.retranslateUi(Form)

QtCore.QMetaObject.connectSlotsByName(Form)

def retranslateUi(self, Form):

_translate = QtCore.QCoreApplication.translate

Form.setWindowTitle(_translate("Form", "Form"))

def paintEvent(self, e):

qp = QPainter()

qp.begin(self)

self.drawLines(qp)

qp.end()

def drawLines(self, qp):

pen = QPen(Qt.black, 2, Qt.SolidLine)

qp.setPen(pen)

qp.drawLine(120, 120, 120, 210)

qp.setPen(pen)

qp.drawLine(135, 94, 120, 120)

qp.setPen(pen)

qp.drawLine(135, 94, 150, 120)

qp.setPen(pen)

qp.drawLine(150, 120, 150, 210)

qp.setPen(pen)

qp.drawLine(120, 210, 150, 210)

if name == "__main__":

import sys

app = QtWidgets.QApplication(sys.argv)

Form = QtWidgets.QWidget()

ui = Ui_Form()

ui.setupUi(Form)

Form.show()

sys.exit(app.exec_())

以上是 pyqt如何在已设置ui窗口里使用qpainter绘图? 的全部内容, 来源链接: utcz.com/p/938343.html

回到顶部