PDA

View Full Version : How can I dock a QDockWidget back to it's starting position



xinor
11th August 2011, 11:38
Hi everybody,

hope someone can help me. I have a widget with a QGraphicsView, QTableView, QListView and a QTreeView. Each of them should be un/dockable. The undocking works, but how can I dock them back to the starting position? I don't want to drag them, I want to press a button and dock them back. Like how I undock them. At the beginning there is a bar with this undock-button. But after the undocking, this bar is gone.
I don't know what I need to do, to dock them back (with a button-press). Here is a bit code. I would be very thankful, if someone could help me out.

Kind regards,
Xinor


# -*- coding: utf-8 -*-
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys

class Example(QWidget):
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.layout = QVBoxLayout()
self.setLayout(self.layout)
self.initUI()

def initUI(self):
self.viewAndTableLayout = QHBoxLayout()
self.dockView = QDockWidget("View")
self.grview = QGraphicsView(self.dockView)
self.dockView.setWidget(self.grview)
self.viewAndTableLayout.addWidget(self.dockView)

self.dockTable = QDockWidget("Table")
self.table = QTableView()
self.dockTable.setWidget(self.table)
self.viewAndTableLayout.addWidget(self.dockTable)
self.layout.addLayout(self.viewAndTableLayout)


self.listAndTreeLayout = QHBoxLayout()
self.dockList = QDockWidget("List")
self.list = QListView()
self.dockList.setWidget(self.list)
self.listAndTreeLayout.addWidget(self.dockList)

self.dockTree = QDockWidget("Tree")
self.tree = QTreeView()
self.listAndTreeLayout.addWidget(self.dockTree)
self.layout.addLayout(self.listAndTreeLayout)

app = QApplication(sys.argv)
ex = Example()
ex.show()
ex.raise_()
sys.exit(app.exec_())

julietbravo
11th August 2011, 11:54
Hi,

I had the same problem; a default 'undock' button to detach the dock, but once it is undocked there is only a close button. I don't know if it is possible to get a 're-dock' button in a dock, I use something like this to restore my docks to their original position:


dock->setFloating(False)

xinor
11th August 2011, 12:33
Hahaha thank you so much julietbravo! I don't know if that is the best way to do it, but it is working :D

xinor
12th August 2011, 10:31
Hi guys,

one more problem. When a widget is undocked/floating and I'm moving the mainwindow, then the floating widget is moving too.
The widgets are also separate by QSplitter and if I'm dragging a splitter, then the floating widgets are resized too.
How can I disable this behavior for the floating/undocked widgets? Is there any way?

Kind regards,
Xinor

Geneosis
5th January 2017, 18:18
Hi all,

Not sure what version of Qt you were using when you posted this thread, anyway there is a way easier solution to make dockwidgets go back to their original location in Qt 4.8 and later versions :
Simply double click the title bar of the floating dockwidget.

d_stranz
6th January 2017, 21:57
Simply double click the title bar of the floating dockwidget.

Well, that's great, but I think the original poster wanted a way to do it with code not the mouse...