PyQt5基础学习-QPainter(绘画组件) 1. self.size(获得当前框的大小) 2. painter.drawPoint(绘制点)

使用painter.drawPoint(x, y)绘制-2pi到2pi的点,

"""
用像素点绘制正弦曲线

-2PI  2PI
drawPoint(x, y)

"""
import sys, math
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import Qt

class DrawPoints(QWidget):
    def __init__(self):
        super(DrawPoints, self).__init__()
        self.resize(300, 300)
        self.setWindowTitle('在窗口上用绘制2个周期的正弦曲线')

    def paintEvent(self, event):
        painter = QPainter(self)
        painter.begin(self)
        painter.setPen(Qt.blue)
        size = self.size()

        for i in range(1000):
            x = 100 * (-1 + 2.0 * i / 1000) + size.width() / 2.0
            y = -50 * math.sin((x - size.width() / 2.0) * math.pi / 50) + size.height() / 2.0
            painter.drawPoint(x, y)
        painter.end()


if __name__ == "__main__":
    app = QApplication(sys.argv)

    main = DrawPoints()
    main.show()

    sys.exit(app.exec_())

PyQt5基础学习-QPainter(绘画组件) 1. self.size(获得当前框的大小) 2.  painter.drawPoint(绘制点)

 

上一篇:Sqlmap入土详解


下一篇:重新安装IDEA后双击启动无反应