diff --git a/pyqtgraph/functions.py b/pyqtgraph/functions.py index b6aae84c..0ef36560 100644 --- a/pyqtgraph/functions.py +++ b/pyqtgraph/functions.py @@ -2060,25 +2060,25 @@ def arrayToQPath(x, y, connect='all', finiteCheck=True): def ndarray_from_qpolygonf(polyline): nbytes = 2 * len(polyline) * 8 - if QT_LIB == "PySide2": - buffer = Qt.shiboken2.VoidPtr(polyline.data(), nbytes, True) - elif QT_LIB == "PySide6": - buffer = Qt.shiboken6.VoidPtr(polyline.data(), nbytes, True) - else: + if QT_LIB.startswith('PyQt'): buffer = polyline.data() + if buffer is None: + buffer = Qt.sip.voidptr(0) buffer.setsize(nbytes) + else: + ptr = polyline.data() + if ptr is None: + ptr = 0 + buffer = Qt.shiboken.VoidPtr(ptr, nbytes, True) memory = np.frombuffer(buffer, np.double).reshape((-1, 2)) return memory def create_qpolygonf(size): - if QtVersion.startswith("5"): - polyline = QtGui.QPolygonF(size) + polyline = QtGui.QPolygonF() + if QT_LIB.startswith('PyQt'): + polyline.fill(QtCore.QPointF(), size) else: - polyline = QtGui.QPolygonF() - if QT_LIB == "PySide6": - polyline.resize(size) - else: - polyline.fill(QtCore.QPointF(), size) + polyline.resize(size) return polyline def arrayToQPolygonF(x, y): diff --git a/tests/test_functions.py b/tests/test_functions.py index 9c0dcb27..e38d8638 100644 --- a/tests/test_functions.py +++ b/tests/test_functions.py @@ -333,3 +333,10 @@ def test_arrayToQPath(xs, ys, connect, expected): continue element = path.elementAt(i) assert eq(expected[i], (element.type, element.x, element.y)) + + +def test_ndarray_from_qpolygonf(): + # test that we get an empty ndarray from an empty QPolygonF + poly = pg.functions.create_qpolygonf(0) + arr = pg.functions.ndarray_from_qpolygonf(poly) + assert isinstance(arr, np.ndarray)