[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] QPainter
From:       David Boddie <david () boddie ! org ! uk>
Date:       2007-06-22 13:38:20
Message-ID: 200706221538.20671.david () boddie ! org ! uk
[Download RAW message or body]

On Fri Jun 22 07:54:17 BST 2007, lucaberto wrote:

> Hello again here's my code but nothing is draw.
> 
>  def on_pushButton_5_clicked(self):
>         re = QtCore.QRect(69, 59, 781, 431)
>         QtGui.QPaintEvent.__init__(re)
>         event = QtGui.QPaintEvent(re)
>         self.paintEvent(event)
>
> def paintEvent(self, event):
>         gr = QtGui.QPainter(self.frame1)
>         gr.setPen(QtGui.QPen(QtCore.Qt.black, 1, QtCore.Qt.SolidLine))
>         gr.drawLine(70,60,740,60)
>         gr.drawLine(70,60, 70, 400)
>         gr.drawLine(70, 230,740, 230)
>         self.frame1.update()

Maybe I wasn't quite clear enough. :-/

You need to subclass QFrame and reimplement its paintEvent() method, not the
paintEvent() method of its parent widget. The subclass could look like this:

class PictureFrame(QFrame):

  def __init__(self, parent = None):
    QFrame.__init__(self, parent)
    self.picture = QPicture()

  def paintEvent(self, event):
    p = QPainter(self)
    p.drawPicture(0, 0, self.picture)

Now, instead of making frame1 a QFrame instance, you could use a PictureFrame
instance and, in your on_pushButton_5_clicked() method, do this instead:

  def on_pushButton_5_clicked(self):
    gr = QPainter(self.frame1.picture)
    gr.setPen(QtGui.QPen(QtCore.Qt.black, 1, QtCore.Qt.SolidLine))
    gr.drawLine(70,60,740,60)
    gr.drawLine(70,60, 70, 400)
    gr.drawLine(70, 230,740, 230)
    self.frame1.update()

David
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic