How to show/hide a whole docking area?
-
Hi,
My application has a few widgets which are docked to the left docking area of my application. Now, there are times where I wish my central widget would get as much real estate as possible. So, in that context, I wish there I could hide all my docked widgets at once, effectively hiding the left docking area (and not hiding each docked widget individually). Ideally, there would be some kind of a button to the right of my left docking area which, when clicked, would either show/hide the whole left docking area. I have googled around a bit for this, but couldn't find anything useful, but I can't imagine this couldn't be done, so... anyone, any idea?
Cheers, Alan.
-
Is it really that onerous to iterate and hide()/show() the dock widgets in the area? About three lines of code in a slot attached to a button toggled() signal.
@
void setDockVisibility(bool visible) {
foreach (QDockWidget dock, findChildren<QDockWidget>())
if (dockWidgetArea(dock) == Qt::LeftDockWidgetArea && !dock->isFloating())
dock->setVisible(visible);
}
@May require one or two more to not show() dock widgets that were already hidden when the visibility was last set to hidden. Other than that your options are limited to hacking into QMainWindow's internal layout I think.
-
Thanks, ChrisW67, but ideally I wouldn't show/hide the individual dock widgets (mainly because I have some menu items which I use to show/hide them, so it would mess things up with regards to my GUI 'logic'). No, ideally, it would be the docking area itself which would get shown/hidden upon clicking a button (a button which, ideally again, would be within the docking area).
-
Hi,
My application has a few widgets which are docked to the left docking area of my application. Now, there are times where I wish my central widget would get as much real estate as possible. So, in that context, I wish there I could hide all my docked widgets at once, effectively hiding the left docking area (and not hiding each docked widget individually). Ideally, there would be some kind of a button to the right of my left docking area which, when clicked, would either show/hide the whole left docking area. I have googled around a bit for this, but couldn't find anything useful, but I can't imagine this couldn't be done, so... anyone, any idea?
Cheers, Alan.
@agarny, I have a different use case that cannot be achieved by iterating over an area's children:
I have two docks in a standard
QVBoxLayout
, and thus have no use forDockWidgetArea
s. Consequently, I want to hide allDockWidgetArea
s except theTopDockWidgetArea
, which I place the docks inside.Currently, my code is the undermentioned:
class InitialWindow(QMainWindow): def __init__(self): central_widget = QWidget() self.setCentralWidget(central_widget) self.addDockWidget(TopDockWidgetArea, toolbar_dock) self.addDockWidget(TopDockWidgetArea, main_content_dock) self.splitDockWidget(toolbar_dock, main_content_dock, QtCore.Qt.Orientation.Vertical) central_layout = QVBoxLayout() central_widget.setLayout(central_layout)
However, the other
DockWidgetArea
s visible causes the undermentioned:-
Padding at the bottom and broken resizability:
-
Useless regions:
I see
AllDockWidgetAreas
, which may be useful?QtCore.pyi
class DockWidgetArea(enum.Flag): LeftDockWidgetArea = ... # type: Qt.DockWidgetArea RightDockWidgetArea = ... # type: Qt.DockWidgetArea TopDockWidgetArea = ... # type: Qt.DockWidgetArea BottomDockWidgetArea = ... # type: Qt.DockWidgetArea AllDockWidgetAreas = ... # type: Qt.DockWidgetArea NoDockWidgetArea = ... # type: Qt.DockWidgetArea
-
-
Thanks @RokeJulianLockhart, but I have (hopefully!) just released the latest version of my Qt application (using Qt 5.12 because I wanted to keep on using QtWebKit, among other things) and I am now using new (more modern, IMO) technologies. I did enjoy my Qt journey though, although not some of the decisions the Qt people made these past few years.