Why does error occur when placing two QVTKRenderWindowInteractor with vtkContextView in a single window in PyQt5 + VTK?

49 views Asked by At

I want to add two seperate interactive vtkChartXY into a single window in PyQt5 + VTK. The window appears and works correctly. However, when it is closed there are several errors.

vtkWin32OpenGLRenderWin:758 ERR| vtkWin32OpenGLRenderWindow (00000254D385E180): failed to get valid pixel format. vtkOpenGLRenderWindow.c:511 ERR| vtkWin32OpenGLRenderWindow (00000254D385E180): GLEW could not be initialized: Missing GL version vtkOpenGLState.cxx:1795 WARN| Hardware does not support the number of textures defined. vtkOpenGLState.cxx:1795 WARN| Hardware does not support the number of textures defined. vtkOpenGLState.cxx:1795 WARN| Hardware does not support the number of textures defined. vtkOpenGLState.cxx:1795 WARN| Hardware does not support the number of textures defined. vtkOpenGLState.cxx:1795 WARN| Hardware does not support the number of textures defined. vtkOpenGLState.cxx:1795 WARN| Hardware does not support the number of textures defined. vtkOpenGLState.cxx:1795 WARN| Hardware does not support the number of textures defined.

Codes:

from vtk import *
from vtkmodules.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
from PyQt5 import QtWidgets

class ChartWidget(QtWidgets.QWidget):
    def __init__(self):
        super().__init__()

        layout = QtWidgets.QVBoxLayout()
        self.setLayout(layout)
        self.iren = QVTKRenderWindowInteractor()
        layout.addWidget(self.iren)

        # x-y plot
        f = vtkPiecewiseFunction()
        f.AddPoint(0, 0.0)
        f.AddPoint(500, 0.5)
        pf = vtkPiecewiseFunctionItem()
        pf.SetPiecewiseFunction(f)

        chart = vtkChartXY()
        chart.AddPlot(pf)

        self.view = vtkContextView()
        self.view.SetRenderWindow(self.iren.GetRenderWindow())
        self.view.GetScene().AddItem(chart)

        self.iren.GetRenderWindow().AddRenderer(self.view.GetRenderer())
        self.iren.GetRenderWindow().Render()

    def closeEvent(self, event):
        super().closeEvent(event)
        self.iren.Finalize()


class MainWindow(QtWidgets.QWidget):

    def __init__(self):
        super().__init__()

        layout = QtWidgets.QHBoxLayout()
        self.setLayout(layout)

        self.w1 = ChartWidget()
        self.w2 = ChartWidget()
        layout.addWidget(self.w1)
        layout.addWidget(self.w2)

    def closeEvent(self, event):
        super().closeEvent(event)
        self.w1.close()
        self.w2.close()


if __name__ == "__main__":
     app = QtWidgets.QApplication(sys.argv)
     mainwindow = MainWindow()
     mainwindow.show()
     app.exec_()
0

There are 0 answers