J-P Nurmi

Native Android style in Qt 5.4

Published Wednesday December 3rd, 2014
16 Comments on Native Android style in Qt 5.4
Posted in Android, Qt, Qt Quick Controls

Qt Quick Controls - Gallery example on Android 4.4

Qt Quick Controls – Gallery example on Android 4.4

As you might have heard, the upcoming Qt 5.4 release delivers a new Android style. This blog post explains what it means in practice for different types of Qt applications.

Qt Widgets

Earlier it has been possible to get native looks for Qt Widgets applications on Android with the help of Ministro, a system wide Qt libraries installer/provider for Android. In Qt 5.4, selected parts of Ministro source code have been incorporated into the Android platform plugin of Qt. This makes it possible for Qt applications to look native without Ministro, even though applications wishing to use services provided by Ministro will continue to do so. In other words, Qt Widgets applications will look native regardless of the deployment method; system wide or bundled Qt libraries.

Qt Quick Controls

The big news is that Qt 5.4 ships a brand new Android style for Qt Quick Controls. A glimpse of the style in action can be seen in the attached screenshot of the Gallery example taken on a Nexus 5 running Android KitKat 4.4. By the way, the Android style requires Android 3.0 (API level 11) or later. On older devices, a generic QML-based fallback style is used instead.

Android 5.0

Android 5.0 preview

DISCLAIMER: work in progress

Mobile platforms keep moving at a fast pace. While we were working hard to deliver a generic native style that works on any Android version 3.0 or later, a new major version of Android was released. Android 5.0 aka Lollipop introduces a new Material design. It comes with so many changes to the underlying platform style, that we haven’t had enough time to catch up with all of those.

Unfortunately, the Material theme support is not yet on an acceptable level. Qt 5.4.0 applications will therefore default to the Holo theme on Android 5.0. The most notable issues are broken disabled states and some missing tint colors, ripple effects and busy/indeterminate animations (QTBUG-42520 and QTBUG-42644).

For the curious ones who cannot wait until the remaining issues have been tackled, it is possible to set the Material theme in AndroidManifest.xml:

<manifest ...>
  <application ... android:theme="@android:style/Theme.Material.Light">
    ...
  </application>
  ...
</manifest>

The same method can be used for setting the light or dark Holo theme for an application, for example. The values are “Theme.Holo.Light” and “Theme.Holo”, respectively.

Do you like this? Share it
Share on LinkedInGoogle+Share on FacebookTweet about this on Twitter

Posted in Android, Qt, Qt Quick Controls

16 comments

Jakub says:

Thanks, nice work!

I’m using Material QML from here: https://github.com/7ymekk/qml-material (my fork), but I don’t like the way these guys are doing it. Instead of using QuickControls they are implementing everything on their own. Works great on Android and Linux though.

LS says:

Great to see the native styling, but it does completely break LineEdits (text not on the edit box, everything misaligned) that worked fine in 5.3. Is there a way to disable the Android native style temporarily?

J-P Nurmi J-P Nurmi says:

Hi, please report the problem to Jira, including a screenshot of the problem and details of the used device.

In order to disable the Android style for a specific control you can do:
TextField { style: TextFieldStyle { } }

For the whole application it can be currently done by setting an environment variable:
qputenv("QT_QUICK_CONTROLS_STYLE", "Base");
in main() before loading the QML.

LS says:

Thanks I’ll report the issue once I’ve had more time to test.

HGH says:

Do QtWidgets support Material design on Android 5? I guess so?

J-P Nurmi J-P Nurmi says:

Compared to controls, widgets currently have a bit more to catch up (QTBUG-42644) with the Material design.

Scorp1us says:

Will the “Material issues” be fixed in a x.x.Y release? Or are they being tabled to a x.Y release?

J-P Nurmi J-P Nurmi says:

We have already prepared some fixes, all of them targeting the 5.4 branch so far.

Leandro says:

Hi guys!

Is in the roadmap native styles for iOS or WPhone too?

Thanks

J-P Nurmi J-P Nurmi says:

Hi Leandro, certainly yes. In fact, iOS already has some things such as text selection handles, copy-paste menu and combobox popup menu done in Qt 5.4.0. The overall styling of individual controls is not yet there, though.

Leandro says:

Ok, thanks Nurmi !
Great work. Keep it up!

Strahlex says:

Is there any documentation on how the SystemPalette can be used properly? I created some custom components and on Android they have now a black background because I used the base color property. A small write-up of what color relates to what part of a component would be nice. It would make cross-platform development a lot easier.

J-P Nurmi J-P Nurmi says:

SystemPalette is basically a QML wrapper around QGuiApplication::palette(). See the QPalette documentation for details about color groups and roles.

What comes to the black color problem, please report a bug if there’s a color role that doesn’t give a sensible color value. This particular problem should’ve been fixed by https://codereview.qt-project.org/#/c/101239/ which went into 5.4.0 just after the RC, though.

Philippe Lelong says:

Hello,
I must be missing something because I cannot seem to be able to get any android style for a qwidget-based application. We were using it though ministro in 5.3.2, and I thought it would become available in 5.4 even when deployed without ministro. Is there something to call or set to get it loaded?

Commenting closed.

Get started today with Qt Download now