magu_ magu_ - 6 months ago 45
Python Question

Add multiple docked widgets

I try to add multiple tabified QDockWidgets but somehow I can only have to docked at the same time.

mwe code:

from PyQt5.QtWidgets import *
from PyQt5.QtCore import *

class DockWindow(QDockWidget):
def __init__(self, parent, name):

parent.addDockWidget(Qt.TopDockWidgetArea, self)
child = parent.findChildren(DockWindow)

if len(child) > 1:
parent.tabifyDockWidget(self, child[0])

app = QApplication(sys.argv)
main = QMainWindow()

for i in range(10):
DockWindow(main, str(i))

enter image description here

Answer Source

According to the docs:

void QMainWindow::tabifyDockWidget(QDockWidget * first, QDockWidget * second)

Moves second dock widget on top of first dock widget, creating a tabbed docked area in the main window.

From what is concluded in the first parameter must be the initial QDockWidget, if any child[0], second the new QDockWidget, in your case self. The problem is solved by changing:

parent.tabifyDockWidget(self, child[0])


parent.tabifyDockWidget(child[0], self)


enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download