rantanplan
rantanplan

Reputation: 3

How to get active QDockWidget in QQMainWindow

I have a QMainWindow containing several QDockWidgets. Each DockWidget contains several other 3rd party Widgets (I don't have access to the source). Some of these Widgets consume focus and mouse events. My problem is to determine when the user clicks on one of the DockWidgets. Installing an eventFilter on the DockWidget won't work, because some of the DockWidget's childs consume the relevant events. Is there a way to determine the "active" DockWidget?

Upvotes: 0

Views: 2142

Answers (1)

Zaiborg
Zaiborg

Reputation: 2522

get the QWidget that has the focus using QApplication::focusWidget().

and you could use something like:

QWidget* wid = QApplication::focusWidget();
QDockWidget* dock = 0;
while (dock != mainWindow && wid != 0)
{
    dock = qobject_cast<QDockWidget*>(wid);
    if (dock)
        break; // its a QDockWidget
    wid = wid->parent();
}

Upvotes: 1

Related Questions