diff options
| author | Ogi Moore <ognyan.moore@gmail.com> | 2022-06-11 08:21:43 -0700 |
|---|---|---|
| committer | Ogi Moore <ognyan.moore@gmail.com> | 2023-01-26 06:58:10 -0800 |
| commit | eb9f91af7e327829bbaa0c6e27440430369ce039 (patch) | |
| tree | ec54b429553acb18b918cc1be5c259d2ef8133b8 /build_scripts/main.py | |
| parent | ed1846b94df1a50ffbac3a8cd82b102e5fe05ce9 (diff) | |
Enable QPainter Draw Methods that Accept Pointers
QPainter draw methods are highly performance sensitive operations, and
it can be the case that users want to draw data that is already
structured in a continuous numpy array. Instead of creating numpy
specific draw methods (such as drawPointsNp) instead we can use the
pointer based methods that are already in the C++ API.
In this case it would go something along the lines of.
size = 10_000 # number of lines
memory = np.empty((size, 4), dtype=np.float64)
lines = shiboken6.wrapInstance(memory.ctypes.data, QtCore.QLineF)
rng = np.random.default_rng()
x = rng.random(size) * size
y = rng.random(size) * size
arr = np.empty((size, 4), dtype=np.float64)
arr[:, 0] = x # x coordinates
arr[:, 1] = y # y coordinates
arr[:, 2] = x + 2
arr[:, 3] = y + 2
memory[:] = arr
qimg = QtGui.QImage(1_024, 1_024, QtGui.QImage.Format.Format_RGB32)
qimg.fill(QtCore.Qt.GlobalColor.transparent)
painter = QtGui.QPainter(qimg)
painter.setPen(QtCore.Qt.GlobalColor.cyan)
painter.drawLines(lines, size)
painter.end()
This method was tested against QPainter.drawPointsNp and was found to
outperform it by a significant margin.
This commit exposes the following method signatures
QPainter.drawPoints(const QPointF*,int)
QPainter.drawLines(const QLineF*, int)
QPainter.drawRects(const QRectF*, int)
Pick-to: 6.4
Fixes: PYSIDE-1924
Change-Id: I844a7bc5fec33673b47228896cb63e4245552a94
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
Diffstat (limited to 'build_scripts/main.py')
0 files changed, 0 insertions, 0 deletions
