[PyQt] Implementing a QPaintEngine

Phil Thompson phil at riverbankcomputing.com
Wed Sep 2 16:39:54 BST 2009


On Wed, 2 Sep 2009 16:17:43 +0100 (BST), Jeremy Sanders
<jeremy at jeremysanders.net> wrote:
> I'm investigating whether it is possible to implement QPaintEngine in
> Python, but I have a problem with my test program:
> 
> -----------------------------------------------
> from PyQt4.QtCore import *
> from PyQt4.QtGui import *
> import sys
> 
> class PaintEngine(QPaintEngine):
> 
>      def begin(self, paintdevice):
>          self.paintdevice = paintdevice
>          return True
> 
>      def drawLines(self, lines, count):
>          print count, lines
> 
>      def end(self):
>          return True
> 
> class PaintDevice(QPaintDevice):
>      def __init__(self):
>          QPaintDevice.__init__(self)
>          self.engine = PaintEngine()
> 
>      def paintEngine(self):
>          return self.engine
> 
> app = QApplication(sys.argv)
> 
> device = PaintDevice()
> p = QPainter(device)
> p.drawLines( [QLineF(0, 0, 100, 100), QLineF(100,100,200,200)] )
> p.drawLine( QLineF(200,200,300,300))
> ----------------------------------------------
> 
> This outputs:
> 
> 2 PyQt4.QtCore.QLineF(0.0, 0.0, 100.0, 100.0)
> 1 PyQt4.QtCore.QLineF(200.0, 200.0, 300.0, 300.0)
> 
> As far as I can see, from the C++ API the first call to drawLines should 
> pass a list of two QLineF objects, but only one is received.
> 
> The C++ documentation says:
>   void QPaintEngine::drawLines ( const QLineF * lines, int lineCount )
> 
> but the PyQt documentation says:
>   QPaintEngine.drawLines (self, QLineF lines, int lineCount)
> 
> Shouldn't lines be a list of QLineF objects?

Yes - and the lineCount argument should be superfluous.

> is this a mistake in the 
> bindings

Yes.

> or am I doing something wrong?

Phil


More information about the PyQt mailing list