[Python] How to fix PySide6 overlay widget showing through collapsed QSplitter sidebar?

Discussão em 'Python' iniciado por Stack, Junho 23, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to build a simple nice looking renderer to make some Graphs for future Projects, therefore I have an overlay with buttons positioned in the top corner of a renderer widget. The renderer is vtk by the way, just if there is a known Problem. When I collapse a sidebar using QSplitter, the overlay shows through the collapsed sidebar, so I see the sidebar, which should be collapsed. I have attached a simplified example of my Problem.

    from PySide6.QtWidgets import (
    QApplication, QMainWindow, QWidget, QSplitter,
    QToolButton, QBoxLayout
    )
    from PySide6.QtCore import Qt
    import vtk
    from vtk.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor

    class Renderer:
    def __init__(self, parent=None):
    # Create the widget and renderer
    self.plotter = QVTKRenderWindowInteractor(parent)
    self.renderer = vtk.vtkRenderer()
    self.renderer.SetBackground(0, 0, 0)

    # Set up the render window
    render_window = self.plotter.GetRenderWindow()
    render_window.AddRenderer(self.renderer)

    # Create interactor style
    self.style = vtk.vtkInteractorStyleTrackballCamera()
    self.plotter.SetInteractorStyle(self.style)
    self.plotter.Initialize()



    class MainWindow(QMainWindow):
    def __init__(self):
    super().__init__()
    self.setWindowTitle("Overlay Issue")

    # Create main splitter
    self.main_splitter = QSplitter(Qt.Horizontal)
    self.left_sidebar = QWidget()
    self.left_sidebar.setStyleSheet("background-color: #303840;")
    self.left_sidebar.setMinimumWidth(200)

    self.renderer = Renderer(self)

    self.main_splitter.addWidget(self.left_sidebar)
    self.main_splitter.addWidget(self.renderer.plotter)
    self.main_splitter.setSizes([300, 600, 300])

    self.setCentralWidget(self.main_splitter)

    # Create overlay with buttons
    self.overlay = QWidget(self.renderer.plotter)
    self.overlay.setStyleSheet("background: transparent;")

    h = QBoxLayout(QBoxLayout.LeftToRight)
    self.overlay.setLayout(h)

    btn = QToolButton()
    btn.setText('text')
    btn.setCheckable(True)
    btn.setStyleSheet("background-color: #0078d4; color: white; border: none;")
    h.addWidget(btn)

    self.overlay.adjustSize()
    self.overlay.move(10, 10)


    if __name__ == "__main__":
    app = QApplication([])
    window = MainWindow()
    window.show()
    app.exec()


    I have tried to replace the vtk renderer with with a QWidget, and it seems that the Problem then dissapears.

    Because on resizing the entire window the problem goes away I tried to call a resize event, which I did not been able to make it work

    Continue reading...

Compartilhe esta Página