help on paint event
Luca Bertolotti
luca72.bertolotti at gmail.com
Thu Oct 29 17:01:38 GMT 2020
Hello i'm not able to paint on my widget:
i wrote this but nothing is painted:
# -*- coding: utf-8 -*-
"""
Module implementing Form.
"""
from PyQt5.QtCore import pyqtSlot, QRect
from PyQt5.QtWidgets import QWidget, QFileDialog
from PyQt5.QtGui import QPainter, QBrush, QPen
from PyQt5.QtCore import Qt
import ezdxf
#from ezdxf.addons.drawing import matplotlib
#from ezdxf.groupby import groupby
import math
from Ui_form import Ui_Form
class Form(QWidget, Ui_Form):
"""
Class documentation goes here.
"""
def __init__(self, parent=None):
"""
Constructor
@param parent reference to the parent widget
@type QWidget
"""
super(Form, self).__init__(parent)
self.setupUi(self)
self.arco = False
self.line = False
@pyqtSlot()
def on_pushButton_clicked(self):
"""
Slot documentation goes here.
"""
# TODO: not implemented yet
#raise NotImplementedError
self.carico_file()
@pyqtSlot()
def on_pushButton_2_clicked(self):
"""
Slot documentation goes here.
"""
# TODO: not implemented yet
raise NotImplementedError
def carico_file(self):
fname = QFileDialog.getOpenFileName(self, 'Open file', None,
("Drawing (*.dxf )"))
doc = ezdxf.readfile(fname[0])
msp = doc.modelspace()
lista_disegno = []
a = 0
for entity in msp:
self.arco = False
self.linea =False
print(entity.dxfattribs())
if entity.dxftype() == 'LINE':
linea_x = entity.dxf.end[0]-entity.dxf.start[0]
linea_y = entity.dxf.end[1]-entity.dxf.start[1]
lista_disegno.append('linea_x'+str(a)+': '+str(linea_x))
lista_disegno.append('linea_y'+str(a)+': '+str(linea_y))
self.x1 = entity.dxf.start[0]
self.y1 = entity.dxf.start[1]
self.x2 = entity.dxf.end[0]
self.y2 = entity.dxf.end[1]
print('linea', self.x1, self.y1, self.x2, self.y2)
a = a+1
self.linea = True
self.update()
if entity.dxftype()=='ARC':
angolo_tot_gradi =
entity.dxf.end_angle-entity.dxf.start_angle
lung_arco=
2*math.pi*entity.dxf.radius/360*angolo_tot_gradi
lista_disegno.append('arco'+str(a)+': '+str(lung_arco))
self.startangle = entity.dxf.start_angle
self.spanangle = lung_arco
xr = entity.dxf.center[0]
yr = entity.dxf.center[1]
r = entity.dxf.radius
self.rectangle = QRect(xr, yr, 2*r, 2*r)
self.arco = True
#self.update()
#self.draw_arc(rectangle, startangle, spanangle)
print(lista_disegno)
self.update()
def paintEvent(self, event):
if self.arco == True:
qp = QPainter()
#qp.begin(self)
pen = QPen(Qt.red, 2, Qt.SolidLine)
qp.setPen(pen)
qp.drawArc(self.rectangle, self.startangle, self.spanangle)
if self.line == True:
qp = QPainter()
pen = QPen(Qt.red, 2, Qt.SolidLine)
qp.setPen(pen)
qp.drawLine(self.x1, self.y1, self.x2, self.y2)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20201029/e67bf316/attachment.htm>
More information about the PyQt
mailing list