I have a class that’s subclassed from QFrame that looks like this
class TestVTKinQFrame(QFrame):
def __init__(self):
super(TestVTKinQFrame, self).__init__()
self.vl = QVBoxLayout()
self.vtkWidget = QVTKRenderWindowInteractor(self)
self.vl.addWidget(self.vtkWidget)
self.ren = vtk.vtkRenderer()
self.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
self.iren = self.vtkWidget.GetRenderWindow().GetInteractor()
# Create source
source = vtk.vtkSphereSource()
source.SetCenter(0, 0, 0)
source.SetRadius(5.0)
# Create a mapper
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(source.GetOutputPort())
# Create an actor
actor = vtk.vtkActor()
actor.SetMapper(mapper)
self.ren.AddActor(actor)
self.ren.ResetCamera()
self.frame.setLayout(self.vl)
# self.setCentralWidget(self.frame)
self.show()
self.iren.Initialize()
And I have a widget that uses this frame
class Widget(QWidget):
def __init__(self):
super().__init__()
# self.model = input_model
self.model = TestVTKinQFrame()
self._top_layout = QHBoxLayout(self)
self._top_layout.addWidget(self.model, stretch=85)
self.setLayout(self._top_layout)
where this widget is added to another layout in a QDialog.
But it keeps crashing for some reason.
If I define it as a class (that’s not subclassed from anything), the VTK render work, but it ends up being very small. Putting addWidget(stretch=90) does nothing for the size.