[PyQt] calling QPainter draw methods efficiently

Luke Campagnola lcampagn at email.unc.edu
Sat May 4 23:58:26 BST 2013


Hello,

Many of QPainter's methods accept arrays of simple classes such as QPoint,
QRect, and PixmapFragment (for eaxmple, drawPoints, drawLines,
drawPixmapFragments, etc). Currently, it is required to pass lists of
wrapped objects to access these methods. This is very inefficient,
especially if the lists contain thousands of items.

I would like to suggest that these methods also accept numpy arrays or
python's built-in arrays and simply pass the pointer to the array data to
the wrapped method. This would vastly improve the performance of graphics
rendering for many cases. I am currently accomplishing this using ctypes to
access the Qt calls directly; it works quite well.

The PySide wrapper should automatically fill in the number-of-elements
arguments based on the byte size of the array and the size of the pointer
argument's structure. For example, for QPainter.drawPoints(QPointF*, int)
the user could pass a numpy array of 20 floats (80 or 160 bytes) and PySide
would automatically determine that the number of elements is 10. It would
be up to the user to ensure that the array is constructed correctly with
two floats per point. (But note that only the byte-size of the array should
be considered; I would recommend against checking the shape and dtype of
the array since there are many different ways to construct these parameters)


Luke
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20130504/a90fda55/attachment.html>


More information about the PyQt mailing list