Working with several QDockWidgets
-
Yes, it doesn't seem to be intended to be used that way. I'm considering alternatives.
I could go with giving each dock widget its own buttons for the TreeView specific actions. But then the question of how to handle keyboard shortcuts would arise.
I also could create my own "active dock widget attribute" and let the user manually set the active dock. Is that a recommended practice? (It might have appeared to you that I'm doing my first steps with Qt ;-)... )
-
Also, I'm not even sure dock widgets can even be "focused" (but the widgets inside them sure can).
-
A dock widget is a widget just like all others. But it is indeed probably more useful to get the focus state of the widgets inside them.
-
I'm hiding the dock widgets on my main window with:
@for w in self.findChildren(QDockWidget):
w.setVisible(True) # or false depending on the case@If I select the 3rd tab in my dock widgets, hide and then re-show them, then the 1st tab will be selected.
If I again hide then show them, then this time the 3rd tab will be selected!So how can I stop that? If I could get the currently selected tab then I could set that one to be active again afterwards. I'm tempted to actually think this might be a Qt Bug... :p
-
I found this:
@void QDockWidget::visibilityChanged ( bool visible ) [signal]This signal is emitted when the dock widget becomes visible (or invisible). This happens when the widget is hidden or shown, as well as when it is docked in a tabbed dock area and its tab becomes selected or unselected.
This function was introduced in Qt 4.3.@
Although quite why there's no method to get that property, I don't know... And it's also not specific enough.
-
There is bound to be a method for the visibility property. A QDockWidget is a QWidget itself. QWidget has the property, so QDockWidget has it as well (probably even requires it).
-
Yeah I don't mean when the dock widget can be seen, but I mean when the dock widget is the selected one on top in a set of tabs.
I wrote this "small example (click here":http://www.qtcentre.org/attachment.php?attachmentid=5397&d=1288020905 - run qmake/make) to show what I mean. Just click show/hide button and notice your currently selected tab position. Is this a Qt bug?
-
Interesting... It seems to be switching to the previously selected widget. Can't say if it's a bug though. I'd need to check a bit more. You could do a search through the bug tracker though.
-
"This":http://bugreports.qt.nokia.com/browse/QTBUG-3420 is the closest bug I could find. Seems QDockWidgets are rather sparse in their api so far :) No way to see who's on top, get the tab orderings, find the layout of several dock widgets in the same area :)
-
-
How can I see if a QDockWidget belongs to a particular tab bar?
EDIT: this "http://doc.trolltech.com/4.7/qtabwidget.html":http://doc.trolltech.com/4.7/qtabwidget.html
(see indexOf(widget))EDIT2: Or not. Spoke too soon!!! QDockWidgets use QTabBar but they don't use QTabWidget! So how am I meant to see which QDockWidget belongs to which QTabBar so I can restore the state? Very frustrating :(
Here is my saving code (saving tab positions)
@ tabWidgetsAll = self.parent().findChildren(QTabWidget, None)
# tab widgets which contain QDockWidget
tabWidgets = []
if len(tabWidgets) > 0:
print 'yay'
for w in widgets:
for tab in tabWidgetsAll:
if tab in tabWidgets:
continue
if tab.indexOf(w) != -1:
tabWidgets.append(tab)
for tab in tabWidgets:
self.activeTabs.append((tab, tab.currentIndex()))@In that snippet 'yay' is never printed, indicating that no QTabWidget's exist and that QDockWidget doesn't use that for tabifying itself.
And here is the restoration code:
@ for tab in self.activeTabs:
tab[0].setCurrentIndex(tab[1])
self.activeTabs = []@ -
any ideas?
-
Can Qt add a QMainWindow::setDockAreaVisible(Qt::DockWidgetArea area, bool visible) to their API?
Looking at:
http://qt.gitorious.org/qt/qt/blobs/4.7/src/gui/widgets/qdockarealayout_p.h
It looks like a trivial change:
add to@
class QDockAreaLayout
{
QDockAreaLayoutInfo hiddenDocks[4]; // hidden dock windows
bool dockHidden[4]; // initialise to false, false, false, false on initialiser
};
QDockAreaLayout::setVisible(QInternal::DockPosition pos, bool visible)if (!visible) {
// copy
hiddenDocks[pos] = docks[pos];
dockHidden[pos] = true;
// clear the dock widget area
docks[pos].clear();
} else {
docks[pos] = hiddenDocks[pos];
}
@And add to QMainWindow::setVisible(area, bool) which does:
layoutState.dockAreaLayout.setVisible(toDockPos(area), bool);
invalidate();Hiding/showing a sidepanel is such a common use-case :) This is a really needed feature.
I made a "bug report here":http://bugreports.qt.nokia.com/browse/QTBUG-14725
-
Maybe it's time to (do a feature request|develop it yourself and do a merge request) for that. I'm not sure these suggestions will be picked up from devnet.
-
Right, but I don't want to waste time building my own Qt, adding that function to the API to have it rejected. Where can I ask whether it would be accepted if the code worked nicely?
-
[quote author="genjix" date="1288186847"]Where can I ask whether it would be accepted if the code worked nicely?[/quote]
Could start with a feature request at "http://bugreports.qt.nokia.com":http://bugreports.qt.nokia.com. Or find the developers on the #qt-labs IRC channel on irc.freenode.net for a chat.