[PyQt] Implementing a QPaintEngine

Jeremy Sanders jeremy at jeremysanders.net
Wed Sep 2 16:17:43 BST 2009

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):
         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? is this a mistake in the 
bindings or am I doing something wrong?



Jeremy Sanders <jeremy at jeremysanders.net>
http://www.jeremysanders.net/                Cambridge, UK
Public Key Server PGP Key ID: E1AAE053

More information about the PyQt mailing list