python pyqt5 QPrinter

-- coding: utf-8 --

''' 【简介】 PyQt5中 涂刷例子

'''

import sys from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtWidgets import * from PyQt5.QtCore import Qt

class Example(QWidget): def init(self): super(Example, self).init() self.initUI() def initUI(self): self.text = "hello world" self.setGeometry(100,100, 400,300) self.setWindowTitle('Draw Demo') self.show()

def paintEvent(self, event):
    qp = QPainter()
    qp.begin(self)
    qp.setPen(QColor(Qt.red))
    qp.setFont(QFont('Arial', 20))
    qp.drawText(10,50, "hello Python")
    qp.setPen(QColor(Qt.blue))
    qp.drawLine(10,100,100,100)
    qp.drawRect(10,150,150,100)
    qp.setPen(QColor(Qt.yellow))
    qp.drawEllipse(100,50,100,50)
    qp.drawPixmap(220,10,QPixmap("./images/python.png"))
    qp.fillRect(200,175,150,100,QBrush(Qt.SolidPattern))
    qp.end()

if name == 'main': app = QApplication(sys.argv) ex = Example() sys.exit(app.exec_())

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

扫码关注云+社区

领取腾讯云代金券