绘图API: 用画刷填充图形区域 的案例
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIcon, QPainter, QBrush
from PyQt5.QtWidgets import QApplication, QWidget
'''
绘图API: 用画刷填充图形区域 的案例
'''
class drawDemo(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
# 设置定位和左上角坐标
self.setGeometry(300, 300, 550, 520)
# 设置窗口标题
self.setWindowTitle('用画刷填充图形区域 的演示')
# 设置窗口图标
# self.setWindowIcon(QIcon('../web.ico'))
def paintEvent(self,e):
qp = QPainter(self)
qp.begin(self)
print("- - -")
brush = QBrush(Qt.SolidPattern)
qp.setBrush(brush)
qp.drawRect(10,15,90,60)
brush = QBrush(Qt.Dense1Pattern)
qp.setBrush(brush)
qp.drawRect(130,15,90,60)
brush = QBrush(Qt.Dense2Pattern)
qp.setBrush(brush)
qp.drawRect(250,15,90,60)
brush = QBrush(Qt.Dense3Pattern)
qp.setBrush(brush)
qp.drawRect(10,105,90,60)
brush = QBrush(Qt.Dense4Pattern)
qp.setBrush(brush)
qp.drawRect(130,105,90,60)
brush = QBrush(Qt.Dense5Pattern)
qp.setBrush(brush)
qp.drawRect(250,105,90,60)
brush = QBrush(Qt.Dense6Pattern)
qp.setBrush(brush)
qp.drawRect(10,205,90,60)
brush = QBrush(Qt.Dense7Pattern)
qp.setBrush(brush)
qp.drawRect(130,205,90,60)
brush = QBrush(Qt.HorPattern)
qp.setBrush(brush)
qp.drawRect(250,205,90,60)
brush = QBrush(Qt.VerPattern)
qp.setBrush(brush)
qp.drawRect(10,305,90,60)
brush = QBrush(Qt.BDiagPattern)
qp.setBrush(brush)
qp.drawRect(130,305,90,60)
brush = QBrush(Qt.CrossPattern)
qp.setBrush(brush)
qp.drawRect(250,305,90,60)
qp.end()
if __name__ == '__main__':
app = QApplication(sys.argv)
# 设置应用图标
app.setWindowIcon(QIcon('../web.ico'))
w = drawDemo()
w.show()
sys.exit(app.exec_())