[Qt-interest] QDockWidget toggle visibility styled
Christian Lackas
delta at lackas.net
Mon Oct 26 08:39:41 CET 2009
Hi Everybody,
I have a bunch of tabbed QDockWidgets, and corresponding buttons in a
QToolBar that should toggle their visibility. If a QDockWidgets is not
visible, I show() and raise() it (the latter one to select its tab),
which works find.
My problem starts, when a QDockWidgets is already visible, but a
different tab is shown. In this case isVisible() is still true, but
rather than hide() I would like to raise() it to The Widget should only
be hidden if it is actually visible to the user.
I already tried
connect(toolBarAction, SIGNAL(triggered()),
dockWidget->toggleViewAction(), SLOT(trigger()));
(which does not help and also does not contain the raise() I need) as
well as
connect(toolBarAction, SIGNAL(triggered()), SLOT(toggleDockView()));
void MainWin::toggleDockView() {
if (dockWidget->isVisible()) {
if (*is actually visible, e.g. tab shown*) { // !!!
dockWidget->hide();
} else {
dockWidget->raise();
}
} else {
dockWidget->show(); dockWidget->raise();
}
}
If I use (in above isVisible branch):
const int cnt = dockWidget->parentWidget()->children().size();
if (cnt < 2) return dockWidget->hide();
const int idx =
dockWidget->parentWidget()->children().indexOf(dockWidget);
if (idx == cnt -1)
dockWidget->hide();
else
dockWidget->raise();
it works for the case described above (widget is topmost), but not for
the case the the QDockWidget is the last one visible (in this case, the
idx is != 0, but also not the last one), which means I have to click the
toggle button twice to hide the last dock widget.
Do I have to add just another exception for this case, or is there a
simpler way to achieve this?
Any insight is appreciated.
Thanks,
Christian
More information about the Qt-interest-old
mailing list