[PyQt] Qpainter last question

David Boddie david at boddie.org.uk
Fri Dec 21 00:36:52 GMT 2007


On Tue, 18 Dec 2007 10:33:57 +0100, lucaberto wrote:

> In the book is write that repaint force the update of the widget.
>
> so i try this :

[...]

> gra = QtGui.QPainter(self.miaPictureFrame.immagine)
> pen = QtGui.QPen()
> pen.setWidth(1)
> gra.setPen(pen)
> gra.drawText(30, 35, '50 daN/mm')
> self.frame1.repaint()
> sleep(3)
> gra.drawText(395, 30, nome_cal)
> gra.drawText(30, 430, '0')
> self.frame1.repaint()

Are self.frame1 and self.miaPictureFrame the same object?

> my Class is:
>
> class PictureFrame(QtGui.QFrame):
>
>     def __init__(self, parent):
>         QtGui.QFrame.__init__(self, parent)
>         self.setGeometry(QtCore.QRect(0,0, 961, 601))
>         self.immagine = QtGui.QPicture()
>      
>     def paintEvent(self, event):
>         gr = QtGui.QPainter(self)
>         gr.drawPicture(0, 0, self.immagine)          
>
> Nothing is paint can you explain me why?

It's difficult to say without being able to run the code and see what is
happening. It could be that you are asking the wrong object to repaint
itself or there could be another problem that we can't see.

Try putting some print statements in the PictureFrame's paintEvent() method
to make sure that it is being called when you expect. If it is then you will
need to find out why the contents of the picture are not being displayed.
If the paintEvent() method is not being called, you will need to check the
code that makes the repaint requests.

David




More information about the PyQt mailing list