Tabbed QDockWidgets: how to fetch the QWidgets "under" a QTabBar ?
-
Hi all,
let's say I have a QMainWindow with 3 QDockWidgets allowed to dock on the same dock area, including in tabbed fashion. I can drag one QDockWidget on top of the other and have the two appear in the same space with a QTabBar automatically created at the bottom. All fine.I can fetch the QTabBar (using findChildren<QTabBar *>() from the QMainWindow) and the QTabBar can tell me how many tabs there are (count) and which tab index is currently selected (currentIndex). But how do I know which QDockWidget (or QWidget) corresponds to, let' s say, tab index 1 ?
Seems a very basic need but I can't find anything ... I must be missing something.
MaX.
-
Hi,
I'd rather search for a QTabWidget and ask for the current widget.
Hope it helps
-
[quote author="SGaist" date="1401565464"]Hi,
I'd rather search for a QTabWidget and ask for the current widget.
[/quote]I tried, there's no QTabWidget, only a QTabBar (that is created and destroyed automatically whenever some QDockWidgets are tabified).
MaX.
-
QStackedLayout/QStackedWidget ?
-
[quote author="SGaist" date="1401570231"]QStackedLayout/QStackedWidget ?[/quote]
None between the children of the QMainWindow.
I have uploaded a minimal Qt Creator example here, if you want to have a look: "QDockWidget - QTabBar":https://drive.google.com/file/d/0BzmU7Qoo77i1UFpiVzBzVDZ2Qjg/edit?usp=sharing
When running, put the 3 QDockWidgets on the left together (tabify them), then hit CTRL-L and it will print some info via qDebug(), including all the children of the main window.
MaX.
-
Looks like it goes down in the guts of QMainWindow. If you want to get the current widget, I'd go with tabifiedDockWidgets and check which one is currently visible.
-
[quote author="SGaist" date="1401654398"]Looks like it goes down in the guts of QMainWindow. If you want to get the current widget, I'd go with tabifiedDockWidgets and check which one is currently visible.[/quote]
Hmmm, no: a tabified qdockwidget is visible even when his tab is not the current one: I can't use "isVisible()" to get which one is current.
Also, if there are two areas that can have tabified widgets (and hence two QTabBar objects), how can one see who's belong to who ?
Seems too big a lack to be true ...
MaX.
-
I must say that I never encountered the need to check which of my QDockWidget were visible when stacked. Can you describe your use case ?
-
It's no big deal in fact: I have two keyboard shortcuts that toggle the visibility of my 2 QDockWidgets. When the widgets are not tabified (i.e. they are either docked alone or floating), this is OK. When they are tabified I can put some code in the actions in order to do nothing (that's easy), but for consistency it would be nicer if the action would make the associated widget current in the QTabBar. But to make the widget current I have to know his index, thing that seems to be not easy to get.
There's probably some sort of dirty workaround checking the "name" of the tab (tabText) and using it to find the widget it belongs to. Still, it seems strange nothing is available for this purpose.
MaX.
-
Are you using the toggleViewAction from QWidget for that ?
-
-
You can try to make a feature request for that on the "bug report system":http://bugreports.qt-project.org
-
[quote author="SGaist" date="1401811706"]You can try to make a feature request for that on the "bug report system":http://bugreports.qt-project.org [/quote]
Just created this: "https://bugreports.qt-project.org/browse/QTBUG-39489":https://bugreports.qt-project.org/browse/QTBUG-39489
MaX.
-