[PyQt] Newbie: get one of several QDockWidgets to perform action on
Hans Meine
meine at informatik.uni-hamburg.de
Tue Oct 5 15:39:22 BST 2010
Am Dienstag 05 Oktober 2010, 13:42:45 schrieb Knacktus:
> I think I need to identify the QDockWidget, which had focus when I
> pressed the button. I've tried the following approaches:
>
> 1) qApp.hasFocus() in my "expand_all()" method --> didn't work, gives
> the focus of the button I pressed
Right, so in the moment you press the button, it first gets focus. Makes
sense. You can still add QActions with shortcuts in order to expand a
specific treeview, but this is too late to get the focus.
So either you follow Hans-Peters suggestion and remember which of the
treeviews *last* had the focus, or you add one such button into every
dockwidget.
Looking from even farther away, you might also expand the views by default, or
add the above-mentioned actions to the dock widgets' (or treeviews') context
menus. (BTW: this is particularly easy with dockWidget.addAction(...)
dockWidget.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu).)
HTH,
Hans
More information about the PyQt
mailing list