importsysfrom PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
classStockDialog(QWidget):def __init__(self, parent=None):
super(StockDialog, self).__init__(parent)
self.setWindowTitle("利用QPainter绘制各种图形")
mainSplitter=QSplitter(Qt.Horizontal)
mainSplitter.setOpaqueResize(True)
frame=QFrame(mainSplitter)
mainLayout=QGridLayout(frame)#mainLayout.setMargin(10)
mainLayout.setSpacing(6)
label1=QLabel("形状:")
label2=QLabel("画笔线宽:")
label3=QLabel("画笔颜色:")
label4=QLabel("画笔风格:")
label5=QLabel("画笔顶端:")
label6=QLabel("画笔连接点:")
label7=QLabel("画刷风格:")
label8=QLabel("画刷颜色:")
self.shapeComboBox=QComboBox()
self.shapeComboBox.addItem("Line", "Line")
self.shapeComboBox.addItem("Rectangle", "Rectangle")
self.shapeComboBox.addItem(‘Rounded Rectangle‘,‘Rounded Rectangle‘)
self.shapeComboBox.addItem(‘Ellipse‘,‘Ellipse‘)
self.shapeComboBox.addItem(‘Pie‘,‘Pie‘)
self.shapeComboBox.addItem(‘Chord‘,‘Chord‘)
self.shapeComboBox.addItem(‘Path‘,‘Path‘)
self.shapeComboBox.addItem(‘Polygon‘,‘Polygon‘)
self.shapeComboBox.addItem(‘Polyline‘,‘Polyline‘)
self.shapeComboBox.addItem(‘Arc‘,‘Arc‘)
self.shapeComboBox.addItem(‘Points‘,‘Points‘)
self.shapeComboBox.addItem(‘Text‘,‘Text‘)
self.shapeComboBox.addItem(‘Pixmap‘,‘Pixmap‘)
self.widthSpinBox=QSpinBox()
self.widthSpinBox.setRange(0,20)
self.penColorFrame=QFrame()
self.penColorFrame.setAutoFillBackground(True)
self.penColorFrame.setPalette(QPalette(Qt.blue))
self.penColorPushButton= QPushButton("更改")
self.penStyleComboBox=QComboBox()
self.penStyleComboBox.addItem("Solid",Qt.SolidLine)
self.penStyleComboBox.addItem(‘Dash‘, Qt.DashLine)
self.penStyleComboBox.addItem(‘Dot‘, Qt.DotLine)
self.penStyleComboBox.addItem(‘Dash Dot‘, Qt.DashDotLine)
self.penStyleComb