×
Namespaces

Variants
Actions
(Difference between revisions)

Detecting focus lost & gained events in Qt for Symbian

From Nokia Developer Wiki
Jump to: navigation, search
Forum Nokia KB (Talk | contribs)
hamishwillee (Talk | contribs)
m (remove Qt for Symbian category - now done with Qt and Symbian category intersection)
Line 1: Line 1:
 +
[[Category:Qt]][[Category:Symbian]][[Category:UI]]
 
__NOTOC__
 
__NOTOC__
 
__NOEDITSECTION__
 
__NOEDITSECTION__
Line 4: Line 5:
 
{{KnowledgeBase
 
{{KnowledgeBase
 
|id=TSQ001585
 
|id=TSQ001585
|platform=S60 3rd Edition, FP1<br>S60 3rd Edition, FP2<br>S60 5th Edition
+
|platform=S60 3rd Edition, FP1<br>S60 3rd Edition, FP2<br>S60 5th Edition<br>Qt 4.6.2
 
|devices=S60
 
|devices=S60
|category=Qt for Symbian (4.6.2)
+
|category=Qt
 
|subcategory=UI
 
|subcategory=UI
 
|creationdate=26 April, 2010
 
|creationdate=26 April, 2010
|keywords=symbianEventFilter
+
|keywords=symbianEventFilter, focus
 
}}
 
}}
  
==Description==
+
==Overview==
  
In Qt for Symbian, detecting foreground application changes, ie. focus lost & gained events, requires reimplementing the <tt>QApplication::symbianEventFilter()</tt> function.
+
{{Abstract|visible=true|This article explains how to detect focus change events in Qt applications on Symbian.}}
 +
 
 +
==Description==
  
This is required because <tt>focusInEvent()</tt>, <tt>focusOutEvent()</tt>, or <tt>hideEvent()</tt> from the <tt>QWidget</tt> class are not called on the Symbian platform when the foreground application changes.
+
Qt applications need to reimplement {{Icode|QApplication::symbianEventFilter()}} in order to get notification of foreground application changes, ie. focus lost & gained events. This is needed because {{Icode|focusInEvent()}}, {{Icode|focusOutEvent()}}, or {{Icode|hideEvent()}} from the {{Icode|QWidget}} class are not called on the Symbian platform when the foreground application changes.
  
 
==Solution==
 
==Solution==
  
Define an application class that inherits <tt>QApplication</tt> and reimplement <tt>symbianEventFilter()</tt>:
+
Define an application class that inherits {{Icode|QApplication}} and reimplement {{Icode|symbianEventFilter()}}:
  
 
<code cpp>
 
<code cpp>
Line 65: Line 68:
 
   };
 
   };
 
</code>
 
</code>
[[Category:Qt for Symbian]][[Category:Qt]][[Category:Technical Solution]][[Category:S60 3rd Edition, Feature Pack 1]][[Category:S60 3rd Edition, Feature Pack 2]][[Category:S60 5th Edition]][[Category:UI]]
+
[[Category:Technical Solution]][[Category:S60 3rd Edition, Feature Pack 1]][[Category:S60 3rd Edition, Feature Pack 2]][[Category:S60 5th Edition]]

Revision as of 08:00, 15 April 2011

Template:KBTS

Article Metadata
Tested with
Devices(s): S60
Compatibility
Platform(s): S60 3rd Edition, FP1
S60 3rd Edition, FP2
S60 5th Edition
Qt 4.6.2
S60 5th Edition
S60 3rd Edition FP2
S60 3rd Edition FP1
Article
Keywords: symbianEventFilter, focus
Created: (26 Apr 2014)
Last edited: hamishwillee (15 Apr 2011)

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
};
125 page views in the last 30 days.