QT MainWindow overlapping with other viewer
This is a small demo. My project is much larger. However, this seems to replicate similar results. I have 2 QVTKRenderWindowInteractors. When I resize them painting bugs appear. In my project's case, one of the windows is just white which should not be happening and the other side widgets seem to be painted into the background of the docking widget which holds the Interactor. I tried to see if the painting events were triggering for my project and I saw that only one of the viewers painting events was going off. I also tried getting the painting event to fire by calling repaint but that didn't seem to work. Again this is just a demo with similar results. When I place 2 normal widgets in the resizing works fine. It seems to be an issue with how vtk connects to QT.
This is a picture of the actual glitch on my application.
This is the error on the demo application:
from PyQt6 import QtWidgets, QtGui, QtCore
import sys
from vtkmodules.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
class CustomWidget(QtWidgets.QWidget):
def __init__(self, parent=None):
super().__init__(parent)
layout = QtWidgets.QVBoxLayout(self)
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(0)
label = QtWidgets.QLabel("Coordinates Label", self)
self.interactor = QVTKRenderWindowInteractor(self)
self.interactor.Initialize()
self.interactor.Start()
layout.addWidget(label)
layout.addWidget(self.interactor)
def trigger_render(self):
if self.interactor:
self.interactor.GetRenderWindow().Render()
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.dock_widget1 = QtWidgets.QDockWidget("Dock 1", self)
custom_widget1 = CustomWidget(self.dock_widget1)
self.dock_widget1.setWidget(custom_widget1)
self.addDockWidget(QtCore.Qt.DockWidgetArea.BottomDockWidgetArea, self.dock_widget1)
self.dock_widget2 = QtWidgets.QDockWidget("Dock 2", self)
custom_widget2 = CustomWidget(self.dock_widget2)
self.dock_widget2.setWidget(custom_widget2)
self.addDockWidget(QtCore.Qt.DockWidgetArea.BottomDockWidgetArea, self.dock_widget2)
self.resize(800, 600)
# Trigger render after the widget has been shown
QtCore.QTimer.singleShot(0, custom_widget1.trigger_render)
QtCore.QTimer.singleShot(0, custom_widget2.trigger_render)
def main():
app = QtWidgets.QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec())
if __name__ == "__main__":
main()