[Python] Why does PyQt6 leave large gap between dock widgets after docking them?

Discussão em 'Python' iniciado por Stack, Maio 3, 2025.

  1. Stack

    Stack Membro Participativo

    I'm using qtpy (wrapping PyQt6) and have a window with dock widgets like so:

    [​IMG]

    However, when I drag and re-dock a dock widget, for some unknown reason the widget redocks with a huge gap between the other dock widget (as indicated by the arrow below):

    [​IMG] [​IMG]

    Any ideas how to avoid this gap? I wonder if it's a Qt6 issue as I don't recall seeing this behaviour in Qt4 or Qt5.

    The full minimal working example is below:

    import sys

    from qtpy.QtCore import Qt
    from qtpy.QtWidgets import QApplication, QMainWindow, QDockWidget, QTextEdit, QComboBox


    class MainWindow(QMainWindow):
    def __init__(self):
    super().__init__()
    self.resize(800, 600)

    central_widget = QTextEdit("Main content area")
    self.setCentralWidget(central_widget)

    dock1 = QDockWidget("Dock 1", self)
    dock1.setWidget(QComboBox())
    dock1.setAllowedAreas(Qt.RightDockWidgetArea)
    dock1.setMinimumWidth(200)

    dock2 = QDockWidget("Dock 2", self)
    dock2.setWidget(QComboBox())
    dock2.setAllowedAreas(Qt.RightDockWidgetArea)
    dock1.setMinimumWidth(200)

    self.addDockWidget(Qt.RightDockWidgetArea, dock1)
    self.addDockWidget(Qt.RightDockWidgetArea, dock2)
    self.setDockOptions(QMainWindow.AnimatedDocks)


    if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()
    app.exec()

    Continue reading...

Compartilhe esta Página