Hi everyone,
I’am trying tu use vtk in a QML project.
I’d like to display my vtk window in a ColumnLayout in my QML but I think I did something wrong because it doesn’t work.
I use VTK 9.2.6
Here is my qml:
import QtQuick 2.9
import QtQuick.Controls 1.4
import QtQuick.Window 2.15
import QtQuick.Layouts 1.15
// import the VTK module
import VTK 9.2
// window containing the application
ApplicationWindow {
id: appWin
// title of the application
title: qsTr("VTK QtQuick App")
width: 1000
height: 800
color: palette.window
SystemPalette {
id: palette
colorGroup: SystemPalette.Active
}
signal value1Signal(val: real)
// menu containing two menu items
menuBar: MenuBar {
Menu {
title: qsTr("File")
MenuItem {
text: qsTr("&Open")
onTriggered: console.log("Open action triggered");
}
MenuItem {
text: qsTr("Exit")
onTriggered: Qt.quit();
}
}
}
// Left Side Zone
Rectangle {
id : leftPanel
anchors.top : parent.top
anchors.left : parent.left
anchors.bottom : parent.bottom
width: 200
color : "#f0f0f0"
ColumnLayout {
anchors.fill: parent
anchors.margins: 10
spacing: 10
Text {
Layout.fillWidth: true
text: "<b>Properties</b>"
}
RowLayout {
spacing: 5
Text {
Layout.fillWidth: true
text: "<i>Value 1 :</i>"
}
Slider {
Layout.fillWidth: true
minimumValue: 0
stepSize: 1
maximumValue: 75
value: 0
updateValueWhileDragging : true
onValueChanged : appWin.value1Signal(value)
}
}
Item {
// spacer item
Layout.fillWidth: true
Layout.fillHeight: true
//Rectangle { anchors.fill: parent; color: "#ffaaaa" } // to visualize the spacer
}
}
}
// Right Side Zone
Rectangle {
anchors.top : parent.top
anchors.left : leftPanel.right
anchors.bottom : parent.bottom
anchors.right : parent.right
ColumnLayout {
anchors.fill: parent
anchors.margins: 10
spacing: 10
Text {
Layout.fillWidth: true
text: "<b>3D View</b>"
}
// Instantiate the vtk render window
VTKRenderWindow {
id: vtkwindow
anchors.top : parent.top
anchors.left : leftPanel.right
anchors.bottom : parent.bottom
anchors.right : parent.right
}
// add one or more vtk render items
VTKRenderItem {
objectName: "VTKView"
x: vtkwindow.x
y: vtkwindow.y
width: vtkwindow.width
height: vtkwindow.height
// Provide the handle to the render window
renderWindow: vtkwindow
}
}
}
}
And in my c++ main:
int main(int argc, char* argv[])
{
Q_INIT_RESOURCE(qml);
QQuickVTKRenderWindow::setupGraphicsBackend();
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl("qrc:/main.qml"));
QObject* topLevel = engine.rootObjects().value(0);
QQuickWindow* window = qobject_cast<QQuickWindow*>(topLevel);
window->show();
// Fetch the QQuick window using the standard object name set up in the constructor
QQuickVTKRenderItem* qquickvtkItem = topLevel->findChild<QQuickVTKRenderItem*>("VTKView");
.......
When I start my application I have many errors in the output, starting by:
2023-06-29 13:16:21.831 ( 2.289s) [ ] vtkOpenGLState.cxx:1171 WARN| Error glGetBoolean1 OpenGL errors detected
0 : (1286) Invalid framebuffer operation