[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: help on paint event
From: Valentin Valls <valentin.valls () esrf ! fr>
Date: 2020-10-29 18:28:22
Message-ID: c8c84af7e4d32e9a491d8c0ba741aacf () esrf ! fr
[Download RAW message or body]
Hi,
Did you try to use QPainter(self)?
I have noticed you have commented painter.begin.
Here you have 2 examples on how to use it with paintEvent
https://doc.qt.io/qt-5/qpainter.html#QPainter-1
Regards,
On 29.10.2020 18:01, Luca Bertolotti wrote:
> 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)
[Attachment #3 (unknown)]
<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>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic