Inherits QQuickItem, and QOpenGLFunctions.
QQuickItem subclass to render a VTK scene in a QtQuick/QML application.
QQuickVTKRenderItem extends QQuickItem so that a VTK visualization pipeline can be rendererd within the rect of the item.
This item is exported to the QML layer via the QQmlVTKPlugin under the module VTK. It is registered as a type VTKRenderItem. The QQuickVTKRenderItem manages a vtkRenderer internally that is rendered as a viewport inside the render window provided by QQuickVTKRenderWindow.
Typical usage for QQuickVTKRenderItem in a Qml application is as follows:
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Window 2.15
import VTK 9.0
ApplicationWindow {
title: qsTr("VTK QtQuick App")
width: 400
height: 400
color: palette.window
SystemPalette {
id: palette
colorGroup: SystemPalette.Active
}
VTKRenderWindow {
id: vtkwindow
width: 400
height: 400
}
VTKRenderItem {
objectName: "ConeView"
x: 200
y: 200
width: 200
}
}
QQuickVTKRenderWindow * renderWindow
The corresponding C++ code that sets up the VTK pipeline would look like the following:
int main(int argc, char* argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicaQtionEngine engine;
engine.load(QUrl("qrc:///<qmlfile>.qml"));
QObject* topLevel = engine.rootObjects().value(0);
QQuickWindow* window = qobject_cast<QQuickWindow*>(topLevel);
window->show();
mapper->SetInputConnection(cone->GetOutputPort());
actor->SetMapper(mapper);
qquickvtkItem->update();
app.exec();
}
QQuickItem subclass to render a VTK scene in a QtQuick/QML application.
vtkRenderer * renderer() const
Get access to the renderer.
static void setupGraphicsBackend()
Set up the graphics surface format and api.
Allocate and hold a VTK object.
void AddActor(vtkProp *p)
Add/Remove different types of props to the renderer.
virtual void ResetCamera()
Automatically set up the camera based on the visible actors.
virtual void SetGradientBackground(bool)
Set/Get whether this viewport should have a gradient background using the Background (bottom) and Bac...
virtual void SetBackground2(double, double, double)
Set/Get the second background color of the rendering screen for gradient backgrounds using an rgb col...
virtual void SetBackground(double, double, double)
Set/Get the background color of the rendering screen using an rgb color specification.
QtQuick scenegraph and threaded render loop
QtQuick/QML scenegraph rendering is done via private API inside the QQuickWindow class. For details on QtQuick's render loop, see QtQuick Scenegraph Rendering. Qt automatically decides between a threaded and basic render loop for most applications. QQuickVTKRenderWindow and QQuickVTKRenderItem support both these variants of the QtQuick render loop.
When the scenegraph render loop is threaded, i.e. there is a dedicated rendering thread, vtk sticks to doing all rendering on this render thread. This means that all the vtk classes, pipelines etc. can be set up on the main thread but vtkRenderWindow::Render should only be invoked on the render thread. Care must be taken not to call Render on the main thread because the OpenGL context would not be valid on the main thread.
Interactive vtk widgets
QQuickVTKRenderItem also supports interactive vtk widgets with QtQuick's threaded render loop via the QQuickVTKInteractiveWidget class.
Definition at line 150 of file QQuickVTKRenderItem.h.