凌的博客

您现在的位置是: 首页 > 学无止境 > python > 

python

38. PyQt6 贝塞尔曲线

2023-10-17 python 644
import sys
from PyQt6.QtWidgets import QApplication, QWidget
from PyQt6.QtGui import QGuiApplication, QPainter, QPainterPath


class App(QWidget):

    def __init__(self):
        super().__init__()
        self.text = None
        self.setMinimumSize(50, 50)
        self.initUI()

    def initUI(self):
        self.setWindowTitle("PyQt6 贝塞尔曲线")

        self.setGeometry(100, 100, 400, 300)
        self.center()

    def paintEvent(self, event):
        qp = QPainter()
        qp.begin(self)
        qp.setRenderHint(QPainter.RenderHint.Antialiasing)
        self.drawBezierCurve(qp)
        qp.end()

    def drawBezierCurve(self, qp):
        path = QPainterPath()

        path.moveTo(30, 30)
        path.cubicTo(30, 30, 200, 350, 350, 30)

        qp.drawPath(path)

    def center(self):
        qr = self.frameGeometry()
        cp = QGuiApplication.primaryScreen().availableGeometry().center()
        qr.moveCenter(cp)
        self.move(qr.topLeft())


if __name__ == "__main__":
    app = QApplication(sys.argv)
    cls_app = App()
    cls_app.show()
    sys.exit(app.exec())

image.png

文章评论

0条评论