When I add two separate interactive vtkChartXY into a single window with PyQt5 and 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.
The errors are similar to the post wglMakeCurrent failed in MakeCurrent after closed a window with two vtk widget., however, the problem still exists when there is vtkContextView.
Here is a demo:
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.widget = QVTKRenderWindowInteractor(self)
layout.addWidget(self.widget)
chart = vtkChartXY()
self.view = vtkContextView()
self.view.SetRenderWindow(self.widget.GetRenderWindow())
self.view.GetScene().AddItem(chart)
# x-y plot
f = vtkPiecewiseFunction()
f.AddPoint(0, 0.0)
f.AddPoint(500, 0.5)
pf = vtkPiecewiseFunctionItem()
pf.SetPiecewiseFunction(f)
chart.AddPlot(pf)
self.view.GetInteractor().Initialize()
self.view.GetInteractor().Start()
def closeEvent(self, event):
super().closeEvent(event)
self.widget.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)
w = MainWindow()
w.show()
app.exec_()