[Qt-interest] Struggling with focus events...
Jaco Naude
naude.jaco at gmail.com
Tue Feb 24 16:00:36 CET 2009
Hi
I'm trying to get my head around focus events. I have an application level
QMainWindow. Inside this main window I have a QMainWindow class which acts
as a frame for other widgets that comes from different plugins by setting
them as the centralWidget() of the QMainWindow frame widget. This allows me
to have control over all widgets received from plugins. These widgets can
either be shown as children of a MDIArea, or as floating windows. I'm trying
to keep track of which window is the active window. This window can either
be inside the MDIArea or floating. Most of my implementation works by
reimplementing the focusInEvent() of my frame window.
The problem now is that the focusInEvent() is only called when I click on
the toolbar or statusbar of the frame widget. To work around this I've tried
to install an event filter on both the centralWidget() and the
parentWidget() if any as follows:
if (centralWidget()) {
centralWidget()->setFocusPolicy(Qt::StrongFocus);
centralWidget()->installEventFilter(this);
}
if (parentWidget()) {
parentWidget()->installEventFilter(this);
parentWidget()->setFocusPolicy(Qt::StrongFocus);
}
And the eventFilter is shown below:
bool ViewerWidgetFrame::eventFilter(QObject *obj, QEvent *event) {
if (obj == centralWidget()) {
if (event->type() == QEvent::FocusIn) {
focusInEvent(0);
return false;
}
} else if (obj == parentWidget()) {
if (event->type() == QEvent::FocusIn) {
focusInEvent(0);
return false;
}
}
return QMainWindow::eventFilter(obj, event);
}
The call to focusInEvent(0) is the focus in event of the frame widget.
At the moment the child widget that I'm testing with is a QTableView on
Windows. If no cells are selected inside the QTableView everthing works.
However if I select some cells in a QTableView, I have to click on the
statusbar or the toolbar of the widget frame. Clicking on the window title,
or inside a different QTableView does not work.
I need to make widgets that come from plugins unaware of what is happening
in the main application, thus I need to control everything at the widget
frame level.
Is this possible,
Thanks in advance for any inputs.
Jaco
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090224/0cbaf30b/attachment.html
More information about the Qt-interest-old
mailing list