<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body style='font-size: 10pt; font-family: Verdana,Geneva,sans-serif'>
<p>Hi,</p>
<p>Did you try to use QPainter(self)?</p>
<p>I have noticed you have commented painter.begin.</p>
<p>Here you have 2 examples on how to use it with paintEvent <a href="https://doc.qt.io/qt-5/qpainter.html#QPainter-1">https://doc.qt.io/qt-5/qpainter.html#QPainter-1</a></p>
<div> </div>
<p>Regards,</p>
<p>On 29.10.2020 18:01, Luca Bertolotti wrote:</p>
<blockquote type="cite" style="padding: 0 0.4em; border-left: #1010ff 2px solid; margin: 0"><!-- html ignored --><!-- head ignored --><!-- meta ignored -->
<div dir="ltr">Hello i'm not able to paint on my widget:
<div>i wrote this but nothing is painted:</div>
<div># -*- coding: utf-8 -*-<br /><br />"""<br />Module implementing Form.<br />"""<br /><br />from PyQt5.QtCore import pyqtSlot, QRect<br />from PyQt5.QtWidgets import QWidget, QFileDialog<br />from PyQt5.QtGui import QPainter, QBrush, QPen<br />from PyQt5.QtCore import Qt<br />import ezdxf<br />#from ezdxf.addons.drawing import matplotlib<br />#from ezdxf.groupby import groupby<br />import math<br /><br /><br />from Ui_form import Ui_Form<br /><br /><br />class Form(QWidget, Ui_Form):<br />    """<br />    Class documentation goes here.<br />    """<br />    def __init__(self, parent=None):<br />        """<br />        Constructor<br />        <br />        @param parent reference to the parent widget<br />        @type QWidget<br />        """<br />        super(Form, self).__init__(parent)<br />        self.setupUi(self)<br />        self.arco = False<br />        self.line = False<br />    <br />    @pyqtSlot()<br />    def on_pushButton_clicked(self):<br />        """<br />        Slot documentation goes here.<br />        """<br />        # TODO: not implemented yet<br />        #raise NotImplementedError<br />        self.carico_file()<br />        <br />    <br />    <br />    @pyqtSlot()<br />    def on_pushButton_2_clicked(self):<br />        """<br />        Slot documentation goes here.<br />        """<br />        # TODO: not implemented yet<br />        raise NotImplementedError<br /><br /><br />    def carico_file(self):<br />            fname = QFileDialog.getOpenFileName(self, 'Open file', None, ("Drawing (*.dxf )"))<br />            doc = ezdxf.readfile(fname[0])<br />            msp = doc.modelspace()<br />            lista_disegno = []<br />            a = 0<br />            for entity in msp:<br />                self.arco = False<br />                self.linea =False<br />                print(entity.dxfattribs())<br />                if entity.dxftype() == 'LINE':<br />                    linea_x = entity.dxf.end[0]-entity.dxf.start[0]<br />                    linea_y = entity.dxf.end[1]-entity.dxf.start[1]<br />                    lista_disegno.append('linea_x'+str(a)+': '+str(linea_x))<br />                    lista_disegno.append('linea_y'+str(a)+': '+str(linea_y))<br />                    self.x1 = entity.dxf.start[0]<br />                    self.y1 = entity.dxf.start[1]<br />                    self.x2 = entity.dxf.end[0]<br />                    self.y2 = entity.dxf.end[1]<br />                    print('linea', self.x1, self.y1, self.x2, self.y2)<br />                    a = a+1<br />                    self.linea = True<br />                    self.update()<br />                if entity.dxftype()=='ARC':<br />                    angolo_tot_gradi = entity.dxf.end_angle-entity.dxf.start_angle<br />                    lung_arco= 2*math.pi*entity.dxf.radius/360*angolo_tot_gradi<br />                    lista_disegno.append('arco'+str(a)+': '+str(lung_arco))<br />                    self.startangle = entity.dxf.start_angle<br />                    self.spanangle = lung_arco<br />                    xr = entity.dxf.center[0]<br />                    yr = entity.dxf.center[1]<br />                    r = entity.dxf.radius<br />                    self.rectangle = QRect(xr, yr, 2*r, 2*r)<br />                    self.arco = True<br />                    #self.update()<br />                    #self.draw_arc(rectangle, startangle, spanangle)<br />                print(lista_disegno)<br />                self.update()<br /><br />    def paintEvent(self, event):<br />        if self.arco == True:<br />            qp = QPainter()<br />            #qp.begin(self)<br />            pen = QPen(Qt.red, 2, Qt.SolidLine)<br />            qp.setPen(pen)<br />            qp.drawArc(self.rectangle, self.startangle, self.spanangle)<br />        if self.line == True:<br />            qp = QPainter()<br />            pen = QPen(Qt.red, 2, Qt.SolidLine)<br />            qp.setPen(pen)<br />            qp.drawLine(self.x1, self.y1, self.x2, self.y2)</div>
</div>
</blockquote>
</body></html>