[PyQt] Upgrading from static to dock widgets?

Matic Kukovec kukovecmatic at hotmail.com
Wed Jun 26 10:33:18 BST 2019


Hi guys,

I have an application that uses three QTabWidgets in a QGroupBox as the central widget.
This works great and I have implemented dragging of tabs between these three widgets.

To upgrade to docking, I would wrap each QTabWidget in a QDockWidget and remove it's titlebar with 'setTitleBarWidget', as I don't want a titlebar. I would also remove the central widget and just have three QDockWidget's docked somewhere.
My questions are:

  *   I would upgrade the QTabWidget to wrap a dragged tab by putting it inside a new QTabWidget and putting it into a QDockWidget automatically on the fly.
How can I then manually initiate a 'dock move' when I drag one of the tabs from a QTabWidget after the dragged tab widget was wrapped as described in the previous sentence?
  *   I tried playing around with QDockWidgets to figure out how to make them movable to any space (above, below, left, right) of any other QDockWidget, but the way in which they can be moved is limited to what area they were initialized in. For example if I add 4 dockwidgets to the QMainWindow with the 'self.addDockWidget(Qt.TopDockWidgetArea, dockwidget)', I can only move them side-by-side, I cannot move one above or below another. What am I missing? My test Example:
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import sys

class Window(QMainWindow):
    def __init__(self):
        super().__init__()

        title = "DockAble Application"
        top = 400
        left = 400
        width = 600
        height = 500

        self.setWindowTitle(title)
        self.setGeometry(top,left, width, height)

        self.dockAble()

    def dockAble(self):
        for i in range(3):
            dock = QDockWidget("Test widget", self)
            dock.setAllowedAreas(Qt.AllDockWidgetAreas)
            self.addDockWidget(Qt.TopDockWidgetArea, dock)

app = QApplication(sys.argv)
window = Window()
window.show()
app.exec()

Thanks,
Matic
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20190626/0ca5e304/attachment.html>


More information about the PyQt mailing list