绘图API: 绘制不同类型的直线 的案例
import math
import sys
from PyQt5.QtCore import Qt, QRegExp, QDir
from PyQt5.QtGui import QIcon, QFont, QPalette, QPixmap, QIntValidator, QDoubleValidator, QRegExpValidator, QPainter, \
QColor, QPen
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QToolTip, QHBoxLayout, QMainWindow, QLabel, QVBoxLayout, \
QDialog, QLineEdit, QGridLayout, QFormLayout, QTextEdit, QRadioButton, QCheckBox, QSlider, QSpinBox, QMessageBox, \
QInputDialog, QFontDialog, QColorDialog, QFileDialog
'''
绘图API: 绘制不同类型的直线 的案例
'''
class drawDemo(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
# 设置定位和左上角坐标
self.setGeometry(300, 300, 400, 250)
# 设置窗口标题
self.setWindowTitle('在窗口上绘制不同的直线 的演示')
# 设置窗口图标
# self.setWindowIcon(QIcon('../web.ico'))
def paintEvent(self,event):
painter = QPainter(self)
painter.begin(self)
print("- - -")
# 画实线
pen = QPen(Qt.red,3,Qt.SolidLine)
painter.setPen(pen)
painter.drawLine(20,40,250,40)
# 画断线
pen.setStyle(Qt.DashLine)
painter.setPen(pen)
painter.drawLine(20,80,250,80)
# 画点线
pen.setStyle(Qt.DashDotLine)
painter.setPen(pen)
painter.drawLine(20,120,250,120)
#画点点线
pen.setStyle(Qt.DashDotDotLine)
painter.setPen(pen)
painter.drawLine(20,160,250,160)
# 画点线
pen.setStyle(Qt.DotLine)
painter.setPen(pen)
painter.drawLine(20,200,250,200)
# 画自定义点线
pen.setStyle(Qt.CustomDashLine)
pen.setDashPattern([1,10,5,4])
painter.setPen(pen)
painter.drawLine(20, 240, 250, 240)
painter.end()
if __name__ == '__main__':
app = QApplication(sys.argv)
# 设置应用图标
app.setWindowIcon(QIcon('../web.ico'))
w = drawDemo()
w.show()
sys.exit(app.exec_())