Detecting focus lost & gained events in Qt for Symbian
hamishwillee
(Talk | contribs) m (Hamishwillee - Bot change of template (Template:KnowledgeBase) - now using Template:ArticleMetaData) |
hamishwillee
(Talk | contribs) m (Hamishwillee - Fix categories) |
||
| Line 1: | Line 1: | ||
| − | [[Category:Qt]][[Category:Symbian]][[Category:UI]] | + | [[Category:Qt]][[Category:Symbian]][[Category:UI]][[Category:Technical Solution]][[Category:S60 3rd Edition, Feature Pack 1]][[Category:S60 3rd Edition, Feature Pack 2]][[Category:S60 5th Edition]][[Category:Symbian C++]] |
__NOTOC__ | __NOTOC__ | ||
__NOEDITSECTION__ | __NOEDITSECTION__ | ||
| Line 6: | Line 6: | ||
|id=TSQ001585 | |id=TSQ001585 | ||
|platform=S60 3rd Edition, FP1<br>S60 3rd Edition, FP2<br>S60 5th Edition<br>Qt 4.6.2 | |platform=S60 3rd Edition, FP1<br>S60 3rd Edition, FP2<br>S60 5th Edition<br>Qt 4.6.2 | ||
| − | |devices= | + | |devices=Symbian |
| − | + | ||
| − | + | ||
|creationdate=26 April, 2010 | |creationdate=26 April, 2010 | ||
|keywords=symbianEventFilter, focus | |keywords=symbianEventFilter, focus | ||
| − | |||
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) --> | |sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) --> | ||
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) --> | |installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) --> | ||
| Line 23: | Line 20: | ||
==Overview== | ==Overview== | ||
| − | {{Abstract | + | {{Abstract|This article explains how to detect focus change events in Qt applications on Symbian.}} |
==Description== | ==Description== | ||
| Line 76: | Line 73: | ||
}; | }; | ||
</code> | </code> | ||
| − | |||
Revision as of 07:15, 16 February 2012
Article Metadata
Tested with
Devices(s): Symbian
Compatibility
Platform(s): S60 3rd Edition, FP1
S60 3rd Edition, FP2
S60 5th Edition
Qt 4.6.2
S60 3rd Edition, FP2
S60 5th Edition
Qt 4.6.2
Article
Keywords: symbianEventFilter, focus
Created: User:Kbwiki
(26 Apr 2013)
Last edited: hamishwillee
(16 Feb 2012)
Overview
This article explains how to detect focus change events in Qt applications on Symbian.
Description
Qt applications need to reimplement QApplication::symbianEventFilter() in order to get notification of foreground application changes, ie. focus lost & gained events. This is needed because focusInEvent(), focusOutEvent(), or hideEvent() from the QWidget class are not called on the Symbian platform when the foreground application changes.
Solution
Define an application class that inherits QApplication and reimplement symbianEventFilter():
#include <QDebug>
#ifdef Q_OS_SYMBIAN
#include <QSymbianEvent>
#include <w32std.h>
#endif
class MyApplication : public QApplication
{
public:
MyApplication( int argc, char** argv ) : QApplication( argc, argv ) {}
#ifdef Q_OS_SYMBIAN
protected:
bool symbianEventFilter( const QSymbianEvent* symbianEvent ) {
const TWsEvent *event = symbianEvent->windowServerEvent();
if( !event ) {
return false;
}
switch( event->Type() ) {
case EEventFocusGained: {
qDebug() << "Focus gained";
break;
}
case EEventFocusLost: {
qDebug() << "Focus lost";
break;
}
default:
break;
}
// Always return false so we don't stop
// the event from being processed
return false;
}
#endif // Q_OS_SYMBIAN
};

