App

The top-level component of a V-Play application containing all other components More...

Import Statement: import VPlayApps 1.0
Inherits:

ApplicationWindow

Properties

Signals

Methods

Detailed Description

The App type is used to create the top-level item in a new V-Play application.

Every V-Play app begins with a single App component defined at the root of its hierarchy. Every app usually includes a single Navigation and some Page items.

Property Documentation

[read-only] diameterInInches : real

This read-only property holds the physical diameter of the screen in inches.

You can use it for example to load different layouts based on the physical size.

Note: The tablet property gets true if this property is bigger than 5.

See also widthInInches, heightInInches, and tablet.


dpScale : real

The scale factor all dp() values are multiplied with.

The default value is 1.

See also dp(), spScale, and uiScale.


[read-only] heightInInches : real

This read-only property holds the physical height of the screen in inches.

You can use it for example to load different layouts based on the physical size.

See also widthInInches and diameterInInches.


[read-only] isOnline : bool

True if the application has access to the internet, false otherwise.

This QML property was introduced in V-Play 2.9.2.


[read-only] landscape : bool

This read-only property gets true if the device is held in portrait mode. This means, the width is bigger than the height.

You can use it for example to load different layouts if the device is in landscape mode.

Note: If landscape is true, portrait will be false and vice versa.

See also portrait and tablet.


licenseKey : string

Set this property to the key you received from http://v-play.net/license/.

You can generate unlimited keys in the V-Play Free Plan and as a V-Play customer.

You need a generated key in order to publish your game.

See also V-Play License.


Whether the V-Play debug menu bar for resolution and theme changing should be set for the app window. By default, the menu bar is only enabled for publishing builds on desktop platforms.

This QML property was introduced in V-Play 2.8.0.


[read-only] portrait : bool

This read-only property gets true if the device is held in portrait mode. This means, the height is bigger than the width.

You can use it for example to load different layouts if the device is in portrait mode.

Note: If portrait is true, landscape will be false and vice versa.

See also landscape and tablet.


screenHeight : real

Set this property together with screenWidth to specify the default size for the app window when running your application on desktop platforms. The screenHeight specifies the height of the content area within the application window. You can use it to simulate resolutions of different devices, the default screen height is 854 px. Only use these properties for initialization purposes, to change the width or height during runtime, use setScreenSize instead.

Note: The actual window may be bigger than the chosen screen size, for example if a menuBar, toolBar or statusBar is used.

This QML property was introduced in V-Play 2.8.0.

See also screenWidth and setScreenSize.


screenWidth : real

Set this property together with screenHeight to specify the default size for the app window when running your application on desktop platforms. The screenWidth specifies the width of the content area within the application window. You can use it to simulate resolutions of different devices, the default screen width is 480 px. Only use these properties for initialization purposes, to change the width or height during runtime, use setScreenSize instead.

Note: The actual window may be bigger than the chosen screen size, for example if a menuBar, toolBar or statusBar is used.

This QML property was introduced in V-Play 2.8.0.

See also screenHeight and setScreenSize.


shutdownAppWithEscapeKeyEnabled : bool

This property holds whether an Escape key press closes the app.

The default value is true for Development Builds on Desktop platforms and false for Publish Builds or mobile platforms.

Thus you can quickly shutdown an app on Desktop with the Esc key during development, where closing and restarting an app is often needed.

Note: You can enable a publish build by setting the property "stage": "publish" in your config.json file.

This QML property was introduced in V-Play 2.8.0.


spScale : real

The scale factor all sp() values are multiplied with.

The default value is 1.

See also sp(), dpScale, and uiScale.


[read-only] tablet : bool

This read-only property gets true if the screen's diameter is bigger than 5 inches.

You can use it for example to load different layouts if the device is a tablet.

See also portrait and landscape.


uiScale : real

The scale factor all dp() and sp() values are multiplied with.

The default value is 1 on mobile and 2 on desktop platforms.

See also dp(), sp(), spScale, and dpScale.


[read-only] widthInInches : real

This read-only property holds the physical width of the screen in inches.

You can use it for example to load different layouts based on the physical size.

See also heightInInches and diameterInInches.


Signal Documentation

applicationPaused()

This signal is emitted when the application is paused. This occurs when the app is moved into the background after pressing the Home button. It is also called when the app is left because the user answers a phone call for example, or when the user locks the screen.

The corresponding handler is onApplicationPaused.

Use this handler to store any app-related data you want to save persistently and should be available to the user after the app is resumed.

If the app got destroyed after the pause, you can then restore the old state when the application starts with Component.onCompleted() or in applicationResumed in case the app was not destroyed but still in the OS memory.

Note: For quick testing of the functionality on desktop systems, you can minimize the application.

As an example, you could put the app into a pause scene once the application is paused. The pause scene could contain a resume button, so the user has enough time to continue with the app after he left the application.

See also applicationResumed.


applicationResumed()

This signal is emitted when the application is resumed after a previous applicationPaused call. It is not called when the application is first started - for this initialization, use the Component.onCompleted() handler.

The corresponding handler is onApplicationResumed.

Use this handler for example to load a previously saved app state. The applicationResumed signal may be called multiple times in an application's lifetime.

See also applicationPaused.


initTheme()

Implement this signal handler to override the app's default theme values on app start. For more information have a look at the Theme global object.


splashScreenFinished()

This handler gets called when the V-Play splash screen was shown and now faded out. It is also called if the license does not require a splash screen, initially at game startup. You can then continue with your game logic in onSplashScreenFinished: ....

Note: A splash screen is only shown in the V-Play Starter License or if you did not set any licenseKey. Upgrade to one of the other licenses to hide the splash screen.


Method Documentation

dp(value)

Returns the density-independent unit for this pixel value.

This allows you to define the same physical size for Item elements across platforms and screens with different densities.

DPI Examples

The dp value is calculated with the following formula: dp = pixel * screenDpi / 160

This means:

  • On a 160 dpi screen like the iPhone 3 (non-retina display), the pixel value of 1 will return 1 dp unit.
  • On a 320 dpi screen like the iPhone 4 (retina display), the pixel value of 2 will return 1 dp unit.

Although the pixel values are different, the physical size of them is the same!

160 dp equals 1 inch. You can calculate the inch value from the pixel value with pixelToInches().

Note: The recommended button height is 48dp. This equals 3/10 of an inch or 0.8 centimeters.

You can modify the result of all dp() function calls by changing the dpScale or uiScale properties.

Example Usage

 import VPlayApps 1.0
 import QtQuick 2.0

 App {
   id: app

   Rectangle {
     width: parent.width
     height: app.dp(48)

     Text {
       text: "20sp"
       font.pixelSize: app.sp(20)
     }
   }
 }

Also see the guide Density Independence Support: dp, sp, pixelToInches, tablet, orientation for more information on density independence. The Android Developers Guide about Supporting Multiple Screens is also a great read to better understand density independence, as the same concepts of Android are used in V-Play.

See also sp(), dpScale, and uiScale.


physicalPixels(pixel)

Returns the pixel value multiplied with the devicePixelRatio of the screen.

On iOS & Mac devices, the reported screen size of App is a virtual point size. To get the real pixels of the screen, a multiplication with devicePixelRatio is needed.

You will mostly not need this value, but it may be useful for debug output or certain scenarios.

Note: The physicalPixels value of the screen is used in V-Play to choose the default V-Play File Selectors to support Dynamic Image Switching.


pixelToInches(pixel)

Returns the value in inches from the pixel value.

You can use the inch value for example to load different layouts based on the physical size.

See also dp(), sp(), widthInInches, heightInInches, diameterInInches, and tablet.


px(value)

internal


setScreenSize(newWidth, newHeight)

Directly modifying the screenWidth and screenHeight properties during runtime can lead to unwanted effects. Use this method to safely change the screen size for the application window during runtime.

This QML method was introduced in V-Play 2.8.0.

See also screenWidth and screenHeight.


sp(value)

Returns the density-independent unit for this pixel value. Only use this function for Text element font.pixelSize values.

This allows you to define the same physical size for Text elements across platforms and screens with different densities.

DPI Examples

The dp value is calculated with the following formula: dp = pixel * screenDpi / 160

This means:

  • On a 160 dpi screen like the iPhone 3 (non-retina display), the pixel value of 1 will return 1 dp unit.
  • On a 320 dpi screen like the iPhone 4 (retina display), the pixel value of 2 will return 1 dp unit.

Although the pixel values are different, the physical size of them is the same!

160 dp equals 1 inch. You can calculate the inch value from the pixel value with pixelToInches().

Note: The recommended button height is 48dp. This equals 3/10 of an inch or 0.8 centimeters.

You can modify the result of all sp() function calls by changing the spScale or uiScale properties.

Note: The only difference to dp() is that you have a different spScale value available to change the scale factor of Text elements. You could read the user settings for font sizes of the system and change it accordingly. This is done by default for native Android applications - you could implement this function yourself by querying the user font settings and then changing the spScale value.

You could also use the spSale to allow users change the font size in your app at runtime, for example with a slider in a settings page.

Example Usage

 import VPlayApps 1.0
 import QtQuick 2.0

 App {
   id: app

   Rectangle {
     width: parent.width
     height: app.dp(48)

     Text {
       text: "20sp"
       font.pixelSize: app.sp(20)
     }
   }
 }

Also see the guide Density Independence Support: dp, sp, pixelToInches, tablet, orientation for more information on density independence. The Android Developers Guide about Supporting Multiple Screens is also a great read to better understand density independence, as the same concepts of Android are used in V-Play.

See also dp(), dpScale, and uiScale.


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