[Python] Cannot Drag Dock Widgets PySide6 Ubuntu 22.04

Discussão em 'Python' iniciado por Stack, Abril 16, 2025.

  1. Stack

    Stack Membro Participativo

    I'm developing a GUI using PySide6 and experiencing an issue with QDockWidgets on Linux Ubuntu 22.04. The dock widgets initialize correctly, but I cannot drag it to a new location. I can click on the header and then move my mouse to another dock location and drop it, but I would like to be able to drag it around as if it was it's own window. I can do this in Windows 11 with no issues, same exact code, but for whatever reason it does not work on Ubuntu.

    Environment


    OS: Ubuntu Linux 22.04 (using Python 3.10.12) Works correctly on: Windows 11 (using Python 3.11.9) (I have tried using a venv on Ubuntu to change the Python version, still no luck) PySide6 version: 6.9.0

    Reproduction


    Create a QMainWindow with QDockWidgets Try to drag the dock by the title bar

    When I try to grab the title bar of a dock widget, I get an error in the console:

    This plugin supports grabbing the mouse only for popup windows.

    Minimal Example For Reproduction


    Here is a code sample that demostrates the issue.

    import sys
    from PySide6.QtWidgets import (QApplication, QMainWindow, QDockWidget,
    QTextEdit, QLabel, QVBoxLayout, QWidget)
    from PySide6.QtCore import Qt

    class MainWindow(QMainWindow):
    def __init__(self):
    super().__init__()
    self.setWindowTitle("QDockWidget Test")
    self.resize(800, 600)

    # Central widget
    central_widget = QWidget()
    central_layout = QVBoxLayout(central_widget)
    central_layout.addWidget(QLabel("Central Widget"))
    self.setCentralWidget(central_widget)

    # Create dock widgets
    self.terminal_dock = QDockWidget("Terminal", self)
    self.terminal_dock.setObjectName("terminal_dock")
    self.terminal_dock.setAllowedAreas(Qt.AllDockWidgetAreas)
    terminal_content = QTextEdit()
    terminal_content.setReadOnly(True)
    terminal_content.setStyleSheet("background-color: black; color: white;")
    terminal_content.setText("$ Terminal (Placeholder)\n$ _")
    self.terminal_dock.setWidget(terminal_content)
    self.addDockWidget(Qt.BottomDockWidgetArea, self.terminal_dock)

    # Additional dock widget
    self.info_dock = QDockWidget("Info Panel", self)
    self.info_dock.setObjectName("info_dock")
    self.info_dock.setAllowedAreas(Qt.AllDockWidgetAreas)
    info_content = QWidget()
    info_layout = QVBoxLayout(info_content)
    info_layout.addWidget(QLabel("Info Panel Content"))
    self.info_dock.setWidget(info_content)
    self.addDockWidget(Qt.RightDockWidgetArea, self.info_dock)

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


    As you can see, you cannot drag the terminal or info panel widgets around.

    I have also tried setfeatures(...) to include moving, floating, and closing but it didn't change anything.

    Continue reading...

Compartilhe esta Página