Add Dock Widgets, Stacked?
-
Alright, another itch I'd like to scratch. How do I add dock widgets programatically that are stacked on top of each other? At the moment, I place 5 calls to place 5 dock widgets like so:
@ this->addDockWidget(Qt::LeftDockWidgetArea, DockA);
this->addDockWidget(Qt::LeftDockWidgetArea, DockB);
this->addDockWidget(Qt::LeftDockWidgetArea, DockC);
this->addDockWidget(Qt::LeftDockWidgetArea, DockD);
this->addDockWidget(Qt::LeftDockWidgetArea, DockE);
@However, they'll all appear one under the other. With this many docks, this isn't really the default behavior I'm keen on. How can I add them stacked on top of each other (with the tabs at the bottom), still allowing users to rearrange them later if they want?
-
[quote author="peppe" date="1293465676"]By using QMainWindow::tabifyDockWidgets.[/quote]
That's the ticket, seems straightforward, thanks :).
Here's another one, how do I choose which tab is currently selected? Or is this purely determined by the order in which they're stacked?
-
There's no API I'm aware of. You have to manually get the QTabBar instance (see QObject::findChildren), figure out which index your QDockWidget have, and call setCurrentIndex on the tab bar. Really strange that the bug has been closed without no explaination:
-
[quote author="peppe" date="1293467757"]There's no API I'm aware of. You have to manually get the QTabBar instance (see QObject::findChildren), figure out which index your QDockWidget have, and call setCurrentIndex on the tab bar. Really strange that the bug has been closed without no explaination:
http://bugreports.qt.nokia.com/browse/QTBUG-1181[/quote]
Ouch, that's a pain in the butt, however nice to know I'm not missing the bleeding obvious (again!). I've just plugged in the following which does the job:
@// Get the tab bar, grab the first one and go to the first tab.
QList<QTabBar*> tabBars = this->findChildren<QTabBar*>();
if(tabBars.count())
{
tabBars.first()->setCurrentIndex(0);
}@Although I agree, this is a bit of a pain in the ass, it would be nice to be able to write:
@
this->raiseDock(theDock);
@
... And have it on top.