Working with several QDockWidgets

when using several QDockWidgets, how do I determine, which is the "active" one? For example, let's take to QDockWidgets which contain a QTreeView each. Now, I'd like to implement an action that generally can work on both docks, but is supposed to work on the one, which is active or had the last focus.

I thought of implementing a method that queries for the active dock before performing the actions. But things like (I'm using pyqt):

I always thought a dock widget was kind of self-contained or affecting an MDI window. The fact that QDockWidget or QMainWindow doesn't really provide an easy way to get to that information kind of suggests to me that the Qt guys didn't intend it to be used that way :). I don't know what the desired behavior of your system is, but I think I would try to find another (maybe nicer) way of handling it.

However, you can probably catch some focus event in each widget and emit a signal that it has received focus.

"Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

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 ;-)... )

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.

"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 :)

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 :(