• 大小: 8KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-14
  • 语言: 其他
  • 标签: QPainter  

资源简介

本资源为QPainter绘制基础图形(二),利用鼠标拖动绘制。

资源截图

代码片段和文件信息

import os
import time
import sys

FileName = os.path.basename(sys.argv[0])
FilePath = sys.argv[0].replace(FileName““)
UiName = FileName.replace(“.py““.ui“)
UiPath = FilePath +UiName
Ui_pyName = FilePath+“ui.py“
FileFlag = os.path.isfile(Ui_pyName)

if FileFlag == 0:
sys_cmd  = os.popen(“pyuic5 “+UiPath+“ -o “+Ui_pyName)
time.sleep(1)

from ui import Ui_Form
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *



class m_window(QWidgetUi_FormQPainter):
def __init__(self):
super(m_windowself).__init__()
self.setupUi(self)
self.pushButton.clicked.connect(self.DrawPoint)
self.pushButton_2.clicked.connect(self.DrawLine)
self.pushButton_3.clicked.connect(self.DrawElipse)
self.pushButton_4.clicked.connect(self.DrawRectangle)
self.pushButton_5.clicked.connect(self.DrawText)
self.pushButton_6.clicked.connect(self.DrawPolygon)
self.pushButton_7.clicked.connect(self.DrawPie)
self.pushButton_8.clicked.connect(self.DrawArc)
self.pushButton_9.clicked.connect(self.DrawPath)
self.Draw = ““
self.Line_list = [0000]
self.Point_list = []
self.Elipse_list = [0000]
self.Rectangle_list = [0000]
self.Polygon_list = []
self.Pie_list = [0000]
self.Arc_list = [0000]

def DrawLine(self):
self.update()
self.Draw = “Line“

def DrawPoint(self):
self.update()
self.Draw = “Point“

def DrawElipse(self):
self.update()
self.Draw = “Elipse“

def DrawRectangle(self):
self.update()
self.Draw = “Rectangle“

def DrawText(self):
self.update()
self.Draw = “Text“

def DrawPolygon(self):
self.update()
self.Draw = “Polygon“

def DrawArc(self):
self.update()
self.Draw = “Arc“

def DrawPie(self):
self.update()
self.Draw = “Pie“

def DrawPath(self):
self.update()
self.Draw = “Path“

def paintEvent(self QPaintEvent):
painter = QPainter(self)
painter.setPen(QColor(16666250))
painter.begin(self)
if self.Draw == “Line“:
painter.drawLine(self.Line_list[0]self.Line_list[1]self.Line_list[2]self.Line_list[3])
print(“DrawLine“)
elif self.Draw == “Point“:
len_point_list = len(self.Point_list)/2
for i  in range(int(len_point_list)):
painter.drawPoint(self.Point_list[i*2]self.Point_list[i*2+1])
print(“DrawPoint“)
elif self.Draw == “Elipse“:
painter.drawEllipse(self.Elipse_list[0]self.Elipse_list[1]self.Elipse_list[2]self.Elipse_list[3])
print(“DrawElipse“)
elif self.Draw == “Rectangle“:
painter.drawRect(self.Rectangle_list[0]self.Rectangle_list[1]self.Rectangle_list[2]self.Rectangle_list[3])
print(“DrawRectangle“)
elif self.Draw == “Text“:
painter.drawText(120120“文字“)
print(“DrawText“)
elif self.Draw == “Polygon“:
polygon = QPolygon()
if len(self.Polygon_list) >= 6:
polygon.setPoints(self.Polygon_list)
print(len(self.Polygon_list))
painter.drawPo

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-07-07 09:42  Darw\
     目录           0  2018-07-07 09:42  Darw\.vs\
     目录           0  2018-07-07 09:42  Darw\.vs\Darw\
     目录           0  2018-07-07 09:42  Darw\.vs\Darw\v15\
     文件       23040  2018-07-07 19:24  Darw\.vs\Darw\v15\.suo
     目录           0  2018-07-07 18:55  Darw\Darw\
     文件         816  2018-07-07 09:42  Darw\Darw.sln
     文件        5881  2018-07-07 18:55  Darw\Darw\Darw.py
     文件        1515  2018-07-07 09:42  Darw\Darw\Darw.pyproj
     文件        3009  2018-07-07 13:18  Darw\Darw\Darw.ui
     文件        2857  2018-07-07 13:22  Darw\Darw\ui.py
     目录           0  2018-07-07 13:22  Darw\Darw\__pycache__\
     文件        1884  2018-07-07 13:22  Darw\Darw\__pycache__\ui.cpython-36.pyc

评论

共有 条评论