[Development] Handling specific platform events in Qt

Gustavsen Richard Richard.Gustavsen at digia.com
Mon Jul 8 14:04:05 CEST 2013


________________________________________
Fra: Alan Alpert [416365416c at gmail.com]
Sendt: 1. juli 2013 22:16
To: Vestbo Tor Arne
Cc: development; Gustavsen Richard
Emne: Re: Handling specific platform events in Qt

On Mon, Jul 1, 2013 at 3:41 AM, Tor Arne Vestbø
<tor.arne.vestbo at digia.com> wrote:
> On 6/28/13 18:59 , Alan Alpert wrote:
>>
>> This should be accessible via Qt.application.active (false if
>> paused/minimized or otherwise not visible).
>
>
> Qt.application.active binds to a window having keyboard activation, AFAIK,
> which may or may not correspond to also being visible/in front, and vice
> versa.

> I don't think so. There's a Window.active property for that, and since we're supporting multi-window Qt.application.active should be referring to global application state.

QWindow::isActive() basically returns if it the window has keyboard focus or not. And QEvent::ApplicationDeactivate is posted by QGuiApplication when no window no longer has keyboard focus. And likewise, a QEvent::ApplicationActivate is posted when at least one window gains focus again.

This coupling of window focus and application activation is not sufficient on mobile platforms, since a window in that environment should only have keyboard focus (with blinking cursors etc) when the virtual keyboard is actually showing. But at the same, the application should not be considered deactivated just because the main window is not active (that is, the virtual keyboard is closed). That, and the fact that we need more than active/inactive to describe the state of an application on mobile platforms, led to the implementation of Qt::ApplicationState.

Currently, the only way to get the application state is to listen for QApplicationStateChangeEvents sent to QGuiApplication. We plan to add a QGuiApplication::applicationState(), and a corresponding QML API for Qt-5.2 as well. In the meantime, since the application state logic also sends out the deprecated QEvent::ApplicationActivate events, you can listen to changes to Qt.application.active as well.

-Richard


More information about the Development mailing list