Feature Request: Expose QPainter methods that accept pointers

Phil Thompson phil at riverbankcomputing.com
Mon Jun 6 17:58:40 BST 2022


On 06/06/2022 17:00, Ognyan Moore wrote:
> Hi Phil,
> 
> We started testing on the updated snapshot from this morning, we're 
> seeing
> improvements but need to alter our own benchmark code to properly 
> capture
> the benefits, so I'll be sending an update in a few days hopefully.
> 
> One thing to note is that we did come across a major performance 
> regression
> on accident (think 80% performance hit) with
> QPainter.drawPolyline(QPolygonF).  While pyqtgraph does not use this
> method, PythonQwt does make extensive use of it and that library would
> likely be significantly impacted by this penalty (which is why I added
> Pierra to this email).
> 
> An example of our use case
> 
> # create data
> x = np. arrange(100)
> y = np.zeros(100)
> 
> # create qpolygonf instance
> size = x.size
> polyline = QtGui.QPolygonF()
> polyline.fill(QtCore.QPointF(), size)
> 
> # get buffer and fill it with original data
> nbytes = 2 * len(polyline) * 8
> buffer = polyline.data()
> buffer.setsize(nbytes)
> memory = np.frombuffer(buffer, np.double).reshape((-1, 2))
> memory[:, 0] = x
> memory[:, 1] = y
> 
> # draw it
> painter.drawPolyline(polyline)
> 
>  If you would like a more complete example you can run let me know.
> 
> Ogi

It's because QPolygonF implements the sequence protocol and so it is 
being broken down and reassembled as an array of QPointF instances. I've 
re-ordered the relevant QPainter methods so that those that take a 
QPolygonF take precedence. (Same for QPolygon and PyQt5.)

Thanks,
Phil


More information about the PyQt mailing list