In my current layout, I have a table in a dock widget that is initially docked (right side). I adjust the contents of the QMainWindow by connecting a function to topLevelChanged() to fill the blank space while floating
self.log_dock.topLevelChanged.connect(self.resize_dock)
def resize_dock(self):
layout = self.tb_utils.findChild(QtWidgets.QLayout)
layout.setExpanded(True)
self.adjustSize()
This works wonderfully - however; after doing so - I'm not entirely sure how to get it to redock to it's original position, or animate to expand the window again. If I manually adjust the QMainWindow slightly, it will allow the dock - or it can be moved into another dock area, and then moved back into position - but this is not ideal.
EDIT: New program using minimal reproducible example
from PyQt5 import uic
from PyQt5.QtWidgets import QApplication, QMainWindow, QLayout
import sys
gui = uic.loadUiType('dock_behavior.ui')[0]
class Window(QMainWindow, gui):
def __init__(self):
super(Window, self).__init__()
self.setupUi(self)
self._connectEvents()
def _connectEvents(self):
self.dockWidget.topLevelChanged.connect(self.resize_dock)
self.show_dock.toggled.connect(self.enable_dock)
def resize_dock(self):
self.adjustSize()
layout = self.toolBar.findChild(QLayout)
layout.setExpanded(True)
def enable_dock(self):
self.dockWidget.toggleViewAction().trigger()
if __name__ == "__main__":
app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())
The GUI as produced by Qt Designer
MainWindow
name="MainWindow">
0
0
825
600
500
600
MainWindow
19
19
461
541
461
541
QFrame::StyledPanel
QFrame::Raised
19
19
411
501
toolBar
Qt::RightToLeft
TopToolBarArea
false
291
0
2
true
Show / Hide Dock
