Theme

A global object for defining app-wide styling attributes. More...

Import Statement: import VPlayApps 1.0
Inherits:

Item

Properties

Methods

Detailed Description

All apps created with V-Play Apps ship with a default style which follows platform-specific attributes. For most flexibility it's however also possible to overwrite these styles by your own.

Example Usage

The most basic example is changing the background color of a navigation bar within a NavigationStack item.

To change a theme-able property implement the App::initTheme signal handler and overwrite the values like in this example:

 import VPlayApps 1.0

 App {
   onInitTheme: {
     // Set the navigation bar background to a shiny blue
     Theme.navigationBar.backgroundColor = "blue"

     // Set the global text color to a dark blue
     Theme.colors.textColor = "#000080"
   }
 }

Note: You can change theme-able properties at any given time from within your app's code, not only in the App::initTheme handler. The recommended approach is however to use the given handler for setting a default style at app start.

How do I change the used platform theme of my app?

The default Theme settings implement platform-specific styles, like the default iOS style on iOS or Material Style on Android, for a native look and feel on both platforms. The following example shows how to manually change the used platform theme in your code:

 import VPlayApps 1.0

 App {

   Navigation {
     NavigationItem {
       title: "Main"
       icon: IconType.heart

       NavigationStack {
         Page {
           title: "Main Page"
           AppButton {
             text: "Switch Theme"
             onClicked: Theme.platform = (Theme.platform === "android") ? "ios" : "android"
             anchors.centerIn: parent

           }
         }
       }
     }

     NavigationItem {
       title: "Second"
       icon: IconType.thlarge

       NavigationStack {
         Page {  title: "Second Page" }
       }
     }
   }
 }

How do I set an app-wide custom font?

V-Play components make use of two different fonts, the Theme::normalFont and the Theme::boldFont. By default, these fonts match the platform's default font for V-Play Apps components.

If you want to explicitly provide your own font you can override the Theme properties with a FontLoader object:

 import VPlayApps 1.0
 import QtQuick 2.5

 App {

   // initialize theme with new font
   onInitTheme: {
     Theme.normalFont = arialFont
   }

   // load new font with FontLoader
   FontLoader {
     id: arialFont
     source: "../assets/fonts/Arial.ttf" // loaded from your assets folder
   }

   Page {
     // V-Play components like AppText automatically use the Theme fonts
     AppText {
       text: "I'm in Arial"
     }
   }
 }

Make sure to add your custom fonts to your app's assets and to provide the correct path in the FontLoader object. You can also use the custom font in your own app components, like the following example:

 Text {
   // Set reference to the global app font
   font.family: Theme.normalFont.name

   text: "Custom text item"
 }

Instead of replacing the general Theme font, you can also use a FontLoader and only overwrite the font.family property for certain text items.

More Frequently Asked Development Questions

Find more examples for frequently asked development questions and important concepts in the following guides:

Property Documentation

appButton : ThemeAppButton

You can override sub-properties of the appButton property to set the global appearance of AppButton items.

Following properties can be overridden:


appCheckBox : ThemeAppCheckBox

You can override sub-properties of the appCheckBox property to set the global appearance of AppCheckBox items. See the documentation of the ThemeAppCheckBox type for an overview of available properties.

This QML property was introduced in V-Play 2.7.1.


[read-only] backgroundColor : color

Read-only alias for colors.backgroundColor.


boldFont : QtObject

Override this property to change the app-wide default bold font. It can either be set to a FontLoader object, or a simple QtObject with a name property, defining the used font name.

If not changed, the default font of an empty Text item is used.


colors : ThemeColors

You can override sub-properties of the colors property to change global colors for the various AppSDK controls.

Following properties can be overridden:


[read-only] controlBackgroundColor : color

Read-only alias for colors.controlBackgroundColor.

This QML property was introduced in V-Play 2.8.2.


[read-only] disabledColor : color

Read-only alias for colors.disabledColor.


[read-only] disclosureColor : color

Read-only alias for colors.disclosureColor.


[read-only] dividerColor : color

Read-only alias for colors.dividerColor.


[read-only] inputCursorColor : color

Read-only alias for colors.inputCursorColor.

This QML property was introduced in V-Play 2.7.0.


[read-only] inputSelectionColor : color

Read-only alias for colors.inputSelectionColor.

This QML property was introduced in V-Play 2.7.0.


[read-only] isAndroid : bool

Read-only property returning true if the app is currently running on an Android device.

You can use this property to change your app's style or logic depending on the underlying platform. The following example shows how to use a different navigation bar color for Android devices:

 import VPlayApps 1.0

 App {
   onInitTheme: {
     // Set the navigation bar background to a shiny blue on Android only
     Theme.navigationBar.backgroundColor = Theme.isAndroid ? "blue" : "red"
   }
 }

[read-only] isDesktop : bool

Read-only property returning true if the app is currently running on an desktop operating system, i.e. Windows, macOS (Mac OS X) or Linux.

You can use this property to change your app's style or logic depending on the underlying platform.


[read-only] isIos : bool

Read-only property returning true if the app is currently running on an iOS device.

You can use this property to change your app's style or logic depending on the underlying platform. The following example shows how to use a different navigation bar color for iOS devices:

 import VPlayApps 1.0

 App {
   onInitTheme: {
     // Set the navigation bar background to a shiny blue on iOS only
     Theme.navigationBar.backgroundColor = Theme.isIos ? "blue" : "red"
   }
 }

[read-only] isLinux : bool

Read-only property returning true if the app is currently running on a Linux operating system.

You can use this property to change your app's style or logic depending on the underlying platform. The following example shows how to use a different navigation bar color for Linux devices:

 import VPlayApps 1.0

 App {
   onInitTheme: {
     // Set the navigation bar background to a shiny blue on Linux only
     Theme.navigationBar.backgroundColor = Theme.isLinux ? "blue" : "red"
   }
 }

[read-only] isOSX : bool

Read-only property returning true if the app is currently running on a macOS (Mac OS X) operating system.

You can use this property to change your app's style or logic depending on the underlying platform. The following example shows how to use a different navigation bar color for macOS devices:

 import VPlayApps 1.0

 App {
   onInitTheme: {
     // Set the navigation bar background to a shiny blue on macOS only
     Theme.navigationBar.backgroundColor = Theme.isOSX ? "blue" : "red"
   }
 }

[read-only] isPortrait : bool

Read-only property returning whether the app is currently in portrait mode. You can use this property to change your app's style based on the interface orientation. It refers to the App::portrait property of your application.

This QML property was introduced in V-Play 2.6.2.


[read-only] isWinPhone : bool

Read-only property returning true if the app is currently running on a Windows Phone device.

You can use this property to change your app's style or logic depending on the underlying platform. The following example shows how to use a different navigation bar color for Windows Phone devices:

 import VPlayApps 1.0

 App {
   onInitTheme: {
     // Set the navigation bar background to a shiny blue on Windows Phone only
     Theme.navigationBar.backgroundColor = Theme.isWinPhone ? "blue" : "red"
   }
 }

[read-only] isWindows : bool

Read-only property returning true if the app is currently running on a Windows operating system.

You can use this property to change your app's style or logic depending on the underlying platform. The following example shows how to use a different navigation bar color for Windows devices:

 import VPlayApps 1.0

 App {
   onInitTheme: {
     // Set the navigation bar background to a shiny blue on Windows only
     Theme.navigationBar.backgroundColor = Theme.isWindows ? "blue" : "red"
   }
 }

listItem : ThemeSimpleRow

You can override sub-properties of the listItem property to set the default appearance of SimpleRow list items. These items are the default component for ListView::delegate when using a ListPage.

The following properties can be overridden:

This QML property was introduced in V-Play 2.6.2.


listSection : ThemeSimpleSection

You can override sub-properties of the listSection property to set the default appearance of ListView sections based on the SimpleSection type. This component is the default type for ListView::section.delegate when using a ListPage.

See the documentation of the ThemeSimpleSection type for an overview of available properties.

This QML property was introduced in V-Play 2.6.2.


listSectionCompact : ThemeSimpleSection

You can override sub-properties of the listSectionCompact property to set the default appearance of ListView sections based on the SimpleSection type, if SimpleSection::style.compactStyle is set to true.

See the documentation of the ThemeSimpleSection type for an overview of available properties.

This QML property was introduced in V-Play 2.6.2.


You can override sub-properties of the navigationAppDrawer property to set the global appearance of Navigation's AppDrawer items.

Following properties can be overridden:

This QML property was introduced in V-Play 2.6.1.


You can override sub-properties of the navigationBar property to set the global appearance of NavigationBar items (e.g. within a NavigationStack).

Following properties can be overridden:


normalFont : QtObject

Override this property to change the app-wide default font. It can either be set to a FontLoader object, or a simple QtObject with a name property, defining the used font name.

If not changed, the default font of an empty Text item is used.


[read-only] placeholderTextColor : color

Read-only alias for colors.placeholderTextColor.


platform : string

This property contains a string representing the current platform the app runs on.

It can also be changed to simulate running on a different platform, for testing purposes.

It has one of the following values:

  • "android"
  • "ios"
  • "winphone"
  • "linux"
  • "osx"
  • "windows"

[read-only] secondaryBackgroundColor : color

Read-only alias for colors.secondaryBackgroundColor.

This QML property was introduced in V-Play 2.6.2.


[read-only] secondaryTextColor : color

Read-only alias for colors.secondaryTextColor.


[read-only] selectedBackgroundColor : color

Read-only alias for colors.selectedBackgroundColor.

This QML property was introduced in V-Play 2.6.2.


[read-only] statusBarHeight : int

Read-only property to retrieve the status bar height of the device, in pixels. If the status bar is hidden, 0 is returned.

This QML property was introduced in V-Play 2.6.1.


[read-only] statusBarStyle : int

Read-only alias for colors.statusBarStyle.


tabBar : ThemeTabControl

You can override sub-properties of the tabBar property to set the global appearance of tabs created with Navigation, TabControl or AppTabBar.

Following properties can be overridden:

  • tabBar.titleColor: The title color defines the font color of the currently selected title label and the icon. Only applies for main-tabs based on NavigationItem.
  • tabBar.titlePressedColor: The pressed color defines the font color of the title label and the icon of tabs when they are being pressed. Only applies for main-tabs based on NavigationItem.
  • tabBar.titleOffColor: The off color defines the font color of the title label and the icon of tabs that are not selected. Only applies for main-tabs based on NavigationItem.
  • tabBar.subTabTitleColor: The title color defines the font color of the currently selected title label and the icon. Only applies for sub-tabs based on AppTabButton.
  • tabBar.subTabTitlePressedColor: The pressed color defines the font color of the title label and the icon of tabs when they are being pressed. Only applies for sub-tabs based on AppTabButton.
  • tabBar.subTabTitleOffColor: The off color defines the font color of the title label and the icon of tabs that are not selected. Only applies for sub-tabs based on AppTabButton.
  • tabBar.backgroundColor: The background color fills the TabControl's background.
  • tabBar.dividerColor: The divider is displayed as a thin line at the very top of the tab bar. Override the divider color to customize the look of the divider.
  • tabBar.height: Height of the tab bar.
  • tabBar.iconSize: The size of the tab icons used for the tab bar.
  • tabBar.showIcon: Whether the specified icon should be shown within a tab.
  • tabBar.textSize: The size of the title displayed for each tab. Only applies for main-tabs based on NavigationItem.
  • tabBar.subTabTextSize: The size of the title displayed for each tab. Only applies for sub-tabs based on AppTabButton.
  • tabBar.fontCapitalization: The Text::font.capitalization setting of the title-
  • tabBar.fontBold: Whether the tab title is displayed bold.
  • tabBar.textMaximumLineCount: The Maximum line count for the title text of each tab.
  • tabBar.markerColor: The color of the bottom line that marks the active tab on Android.

[read-only] textColor : color

Read-only alias for colors.textColor.


[read-only] tintColor : color

Read-only alias for colors.tintColor.


Method Documentation

reset( = softReset)

Reset the default Theme. This discards any changes made to the Theme.


Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support