Best way to 'customise' the docking areas of a QMainWindow?
-
Hi,
My application's main form inherits from QMainWindow and I rely on QMainWindow's docking feature to dock some widgets to my main form. It all works fine and everything, but... I would like to be able to show/hide a docking area by simply clicking a button within the docking area.
The idea is that the user might have customised the main form with some widgets docked here and there. However, he might at some point want the central widget to get as much space as possible to carry out a particular task. So, I would like him to be able to temporarily hide one or several docking areas, carry out his particular task, and then re-show those one or several docking areas.
I know that I could 'manually' show/hide the dock widgets (after/before saving/restoring my application's state), but this would 'break' my GUI logic since I have some menu items which I use to show/hide those dock widgets. Also, this wouldn't address the question of how this 'showing'/'hiding' would be triggered which I want to be done through a button within the docking area.
So... I was thinking of customising QMainWindow's docking feature so that it could do what I am after. However, with Qt implementating QMainWidnow's docking feature in private classes means that I cannot customise anything. I am therefore thinking of 'cloning' QMainWindow (and whatever would need 'cloning'), renaming the clone to, say, TMainWindow, customising TMainWindow to my specific needs, and then have my main form inherit from TMainWindow rather than QMainWindow.
If at all possible, I would rather not go down that route, but what other options are available to me?... Anyone?...
Cheers, Alan.
-
Hi,
Are you thinking about some sort of tool bar/ menu that would use "QDockWidget's toggleViewAction":http://qt-project.org/doc/qt-4.8/qdockwidget.html#toggleViewAction ?
-
[quote author="SGaist" date="1368435427"]Are you thinking about some sort of tool bar/ menu that would use "QDockWidget's toggleViewAction":http://qt-project.org/doc/qt-4.8/qdockwidget.html#toggleViewAction ?[/quote]I do indeed have a menu, in my main form, which lists the different dock widgets and their visible state through a checkbox which gets checked/unchecked whenever toggleViewAction() emits the toggled() signal.
This being said, this is not what I am talking about here. I want to show/hide a whole docking area (incl. any dock widgets it currently contains).
-
One thing you could do is have 5 "hiding" actions one for each area and one for all.
Then in a slot, search for all dock widget being in that area using "findChildren":http://qt-project.org/doc/qt-4.8/qobject.html#findChildren and "docWidgetArea":http://qt-project.org/doc/qt-4.8/qmainwindow.html#dockWidgetArea then and toggle their visibility
-
I have already tried findChildren and docWidgetArea (together with saving/restoring my application’s state), and though it does indeed work, it's not a suitable option.
I mean, it updates the checkbox associated with the menu items that I have to show/hide a particular dock widget, while when hiding a docking area I don't want the dock widgets it contains to be considered hidden. It's the docking area which is hidden not its dock widgets as such.
Then, considering the left docking area, I would like a button to be to the left of the splitter between the left docking area and the central widget. The button would show a glyph that makes it clear that if it was to be clicked then the docking area would be shown/hidden.