[Python] How to resolve conflict between vtk interactor and dockwidget connected to...

Discussão em 'Python' iniciado por Stack, Agosto 29, 2025.

  1. Stack

    Stack Membro Participativo

    I want the centralwidget to fill the main window depending on the docking and floating states of the dockwidget. I solved the problem with this code, without using VTK.

    However, when I connect the VTK interactor to the centralwidget, the centralwidget doesn't fill the main window. I think there's a conflict between VTK and the dockwidget. Please let me know if there's a way to fix this or another way to achieve what I want.

    import sys
    from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QDockWidget, QTextEdit
    from PyQt5.QtCore import Qt

    class MainWindow(QMainWindow):
    def __init__(self):
    super().__init__()
    self.setWindowTitle("Multiple DockWidgets")

    self.vtkv=VtkView()
    self.setCentralWidget(self.vtkv.interactor)

    self.docks = {}

    dock_widget1 = QDockWidget("Dock Widget 1", self)
    dock_widget1.setWidget(QTextEdit("Content for Dock 1"))
    self.addDockWidget(Qt.RightDockWidgetArea, dock_widget1)
    self.docks['dock1'] = dock_widget1

    dock_widget2 = QDockWidget("Dock Widget 2", self)
    dock_widget2.setWidget(QTextEdit("Content for Dock 2"))
    self.addDockWidget(Qt.LeftDockWidgetArea, dock_widget2)
    self.docks['dock2'] = dock_widget2

    for key, dock in self.docks.items():
    # Use a lambda function to pass the dock object to the handler
    dock.visibilityChanged.connect(lambda visible, d=dock: self.on_dock_visibility_changed(visible, d))

    def on_dock_visibility_changed(self, visible, dock):
    pass

    class VtkView:
    def __init__(self):
    self.ren=vtkRenderer()
    self.interactor=self.GetRenderWindow().GetInteractor()

    if __name__ == "__main__":
    app = QApplication(sys.argv)
    main_window = MainWindow()
    main_window.show()
    sys.exit(app.exec_())

    Continue reading...

Compartilhe esta Página