Add Python implementations of `QVTK` Classes to `vtkmodules`
Using vtkmodules.qt.QVTKRenderWindowInteractor
with QVTKRWIBase = 'QOpenGLWidget'
gives the error
QPainter::begin: Paint device returned engine == 0, type: #
where #
is the corresponding QPaintEngine Type. This occurs because the paintEngine()
is overriden to return None
and WA_PaintOnScreen
is set to support rendering outside Qt's paint system, but WA_PaintOnScreen
only is only supported on X11
systems.
Both VTK
and Qt
(since Qt version 4; see also this) support double-buffering by default. Thus, VTK
maintains its own OpenGL context (front and back buffer) as does Qt
. WA_PaintOnScreen
was set so we may draw straight to Qt
's front buffer (disabling Qt
's back buffer) and avoid display flickering.
The VTK
C++ source contains QVTK
classes to integrate with QOpenGLWidget
and overcome these issues, but these have not been wrapped in Python.
Due to licensing restrictions and existing differences between the different existing python Qt
bindings and versions (Qt
objects would have to be wrapped with sip
(for PyQtX) or shiboken
(for PySideX), which would require creating separate python vtk
packages for each Qt
python binding), a pure python implementation is preferred.
Developer Notes
-
For ease of review (and to maintain the same interface), the names and casing of variables, functions, and classes has been preserved (even though they are not all pythonic) -
The Python Wrapper notes and VTK Code Style Guide were followed (to the best of my ability) when translating the C++ source into Python. I attempted to make the translation as close to 1:1 as possible, again for ease of reviewing.
Topics for Discussion
-
Adding QtPy, packaging, and PyOpenGL dependencies? -
Use of @property
decorators for setters/getters, or keep set/get methods for a consistent interface? -
Use of more pythonic variable naming, or keep same convention for same interface? -
Modify QVTKRenderWindowInteractor
to not useWA_PaintOnScreen
so double-buffering is enabled?
Additional Tasks
-
Add unittest
tests in theWrapping/Python/Testing
subfolder -
Raise error if user does not have qtpy
orpyopengl
installed
Thoughts
-
Emulate QScopedPointer
s andQScopedValueRollback
s with context managers (i.e.__enter__
,__exit__
)
Useful Links
-
Qt C++ source code on GitHub: (refer to
openglwidgets
,opengl
, andgui
) - Qt6.3 OpenGL Window Example
- PySide6 Threaded QOpenGLWidget Example
- PySide6 OpenGL Context Info Example
- Qt OpenGL Tutorial
Related Issues:
Mayavi:
PyVistaQt:
⚠ Note:
The example is run against the latest PyPI
version of vtkmodules
, which is 9.1.0
. If additional changes included in the 9.2.0
release candidates or nightly builds are needed for this to work, please let me know.
I am attempting to get an equivalent version of the QVTKRenderWidgetConeExample
to work, but setAlphaBufferSize(8)
in defaultFormat
causes the entire window to be transparent. Note that this happens whether CoreProfile
or CompatibilityProfile
is set. This is what happened in ParaView #17159, but method clearAlpha()
from MR 2502 does not work in PySide6
since several QOpenGLFunctions
are either missing or broken. See:
A workaround will be required, either using PyOpenGL
or ctypes
to add the missing functions to QOpenGLFunctions
. This problem may or may not be due to the listed QOpenGLWidget Limitations. If I set WA_AlwaysStackOnTop
however, I get a pure white background. Please provide whatever help you can for this. The cone code example is in QVTKOpenGLNativeWidget.py
, so that file can be run directly to run the example.
Potentially Related:
- Window resizing not working with QVTKRenderWindowInteractor under Linux
- BUG: vtkBalloonWidget invisible text with QVTKOpenGLWidget
- QVTKOpenGLWidget with vtkBalloonWidget leads to black window when focus is changing
- Qt support: add mode to make Qt widget request VTK renders on paint, Qt widgets refacvtor !5214
- QVTKOpenGLWidget can not be built on platforms with GLES Qt builds
- Qt5 + Mesa: Render Windows appears translucent
Ancillary Issues (Still Open):
- BUG: Memory not garbage collectible when more than one Qt window open at once
- Actor with opacity shows through opaque actor in 9.1 (not in 8.1)
- Python QGLWidget interactor hangs on VTK9 RC3 wheels on Linux with PyQt < 5.14.1
- QVTKOpenGLNativeWidget breaks painting of parent QWidget and all siblings
- VTK 8.2.0 + Qt 5.12.2 weird event queue processing
- Rendering offscreen causes the window to no longer render.
- Antialiasing issue in fullscreen QVtkOpenGLWidget
- vtkWin32OpenGLRenderWindow: window size for offscreen rendering for OpenGL2
- Crash related to vtkRenderWindow::SetOffScreenRendering
Requested Reviewers:
VTK:
Cc: David Gobbi ( @dgobbi ), Mathieu Westphal ( @mwestphal ), Sankhesh Jhaveri ( @sankhesh ), Ken Martin ( @ken-martin ), Will Schroeder ( @will.schroeder ), Lucas Givord ( @lucas.givord )
PyVista:
Cc: Eric Larson ( @larsoner ), Alex Kaszynski ( @akaszynski ), Bane Sullivan ( @banesullivan ), Guillaume Favelier ( @GuillaumeFavelier )
Mayavi:
Cc: Prabhu Ramachandran ( @prabhuramachandran ), Marijn van Vliet ( @wmvanvliet )
Fixes #18606 .