C++ widget in PySide6 application
-
It looks like my PySide6 application is somewhat slow in drawing so I am considering moving my problematic Qt widget to the C++ python extension.
It should definitely be possible because entire C++ Qt is available for Python :)
But is this supported or recommended for custom widgets?
Thanks!
-
Are you using OpenGL or QPainter-based drawing?
For example, there is QPainter.drawPointsNp() which takes 2 numpy-arrays:
For OpenGL, the QOpenGLFunctions typically also take numpy arrays.
Nevertheless, creating Python bindings for a Custom widget is also possible with shiboken. It just takes some thought on how to structure it. You might want a C++ library containing the widget, a separate Qt Designer plugin and the bindings.
For generating bindings. see for example
https://doc.qt.io/qtforpython-6/examples/example_scriptableapplication__scriptableapplication.html -
It looks like my PySide6 application is somewhat slow in drawing so I am considering moving my problematic Qt widget to the C++ python extension.
It should definitely be possible because entire C++ Qt is available for Python :)
But is this supported or recommended for custom widgets?
Thanks!
@dmytro-16384
Hello and welcome.PySide/PyQt are only wrappers around Qt code for Python. Are you sure your "slowness" is in the Python code rather than the time it takes to do whatever Qt drawing or even your algorithm?
-
@JonB said in C++ widget in PySide6 application:
PySide/PyQt are only wrappers around Qt code for Python. Are you sure your "slowness" is in the Python code rather than the time it takes to do whatever Qt drawing or even your algorithm?
I think slowness is in my python draw code. I'm drawing a lot (1000s) of small lines and preparing QPoints lists seems takes some time in Python. I tried obvious optimisations like re-using point objects and had some improvements but anyway it takes up to 100ms to update a frame.
Drawing itself should be quite cheap if I understand correctly, it should directly be mapped to the Open GL draw call.
So the next thing I want to try is moving this code to C++ if possible.
Thanks!
-
Are you using OpenGL or QPainter-based drawing?
For example, there is QPainter.drawPointsNp() which takes 2 numpy-arrays:
For OpenGL, the QOpenGLFunctions typically also take numpy arrays.
Nevertheless, creating Python bindings for a Custom widget is also possible with shiboken. It just takes some thought on how to structure it. You might want a C++ library containing the widget, a separate Qt Designer plugin and the bindings.
For generating bindings. see for example
https://doc.qt.io/qtforpython-6/examples/example_scriptableapplication__scriptableapplication.html -
Are you using OpenGL or QPainter-based drawing?
For example, there is QPainter.drawPointsNp() which takes 2 numpy-arrays:
For OpenGL, the QOpenGLFunctions typically also take numpy arrays.
Nevertheless, creating Python bindings for a Custom widget is also possible with shiboken. It just takes some thought on how to structure it. You might want a C++ library containing the widget, a separate Qt Designer plugin and the bindings.
For generating bindings. see for example
https://doc.qt.io/qtforpython-6/examples/example_scriptableapplication__scriptableapplication.html@friedemannkleint said in C++ widget in PySide6 application:
QPainter.drawPointsNp
Thank you for your hints. The QPainter.drawPointsNp looked promising, but I need lines :) I even constructed a hack using QXYSeries which also accepts Numpy arrays and can return QPoints, but unfortunately prebuilt PySide6 comes without any Numpy support (why???). Rebuilding PySide and support custom version looks like an overkill for me for now.
I'm really appreciate your help, thank you for the links I will give them a try.
-
@friedemannkleint said in C++ widget in PySide6 application:
QPainter.drawPointsNp
Thank you for your hints. The QPainter.drawPointsNp looked promising, but I need lines :) I even constructed a hack using QXYSeries which also accepts Numpy arrays and can return QPoints, but unfortunately prebuilt PySide6 comes without any Numpy support (why???). Rebuilding PySide and support custom version looks like an overkill for me for now.
I'm really appreciate your help, thank you for the links I will give them a try.
@dmytro-16384 PySide 6.4 will have numpy support built-in.