Qt Quick Components

Screen

  • List of all members, including inherited members
  • Properties

    Detailed Description

    This class provides access to the screen properties, like the resolution, the orientation and the dpi.

    Screen is exposed as a context property called "screen". It is not possible to instantiate a Screen object in QML, but the screen must be accessed through the context property.

    Property Documentation

    allowedOrientations : enumeration

    TODO. This is a flags type property. Check that qdoc recognizes it correctly.

    The allowed orientations for the screen. The property accepts any combination of Screen::Orientations flags.

    • Screen.Default - the default set of allowed orientations, may depend on hardware
    • Screen.Portrait - portrait mode allowed
    • Screen.Landscape - landscape mode allowed
    • Screen.PortraitInverted - inverted portrait mode allowed
    • Screen.LandscapeInverted - inverted landscape mode allowed
    • Screen.All - convenience enumeration for allowing all possible orientation modes

    The property can be used for locking the screen to a certain orientation, like this:

     function lockToLandscape() {
         screen.allowedOrientation = Screen.Landscape
     }

    Or it can be used for letting the orientation change freely according to the actual physical orientation of the device, like this:

     function setAutomaticOrientation() {
         screen.allowedOrientation = Screen.All
         // equals to:
         // screen.allowedOrientation = Screen.Portrait | Screen.Landscape |
         //                             Screen.PortraitInverted | Screen.LandscapeInverted
     }

    Notice that typically orientation is controlled by the Page component. This property should be used explicitly only if Page is not used at all, or if Page::orientationLock property is set to PageOrientation.Manual.

    See also currentOrientation and Page::orientationLock.


    currentOrientation : enumeration

    The current orientation of the screen. The possible values are:

    • Screen.Portrait - when the width of the screen is less than or equal to the height
    • Screen.Landscape - when the width of the screen is greater than the height
    • Screen.PortraitInverted - when the width of the screen is less than or equal to the height, and the screen is considered to be upside-down
    • Screen.LandscapeInverted - when the width of the screen is greater than the height, and the screen is considered to be upside-down

    The actual possible values may depend on hardware. For instance, some devices might support only one orienation, or some devices might not support inverted orientations.

    Notice that this is a read-only property. For setting the orientation use allowedProperties or Page::orientationLock

    See also allowedOrientations and Page::orientationLock.


    density : enumeration

    Screen classification based on the dpi value of the screen.

    // TODO. How to document the limits of the categories if we do not want to expose the // accurate limits?

    • Screen.Low - a low-dpi screen
    • Screen.Medium - a medium-dpi screen
    • Screen.High - a high-dpi screen
    • Screen.ExtraHigh - an extra-high-dpi screen

    See also displayCategory.


    displayCategory : enumeration

    Screen classification based on the physical size (diagonal) of the screen.

    This property property can be used e.g. for selecting different top level layouts for different display categories:

     Page {
         Loader {
             source: (screen.displayCategory == Screen.Small) ? "SmallView.qml" : "NormalView.qml"
             ...
         }
     }

    // TODO. How to document the limits of the categories if we do not want to expose the // accurate limits?

    • Screen.Small - a small screen
    • Screen.Normal - a normal screen
    • Screen.Large - a large screen
    • Screen.ExtraLarge - an extra large screen

    See also density.


    displayHeight : int

    The native height of the display, i.e. the height of the screen when rotation returns zero.

    See also height and rotation.


    displayWidth : int

    The native width of the display, i.e. the width of the screen when rotation returns zero.

    See also width and rotation.


    dpi : qreal

    The dots per inch value of the screen. It is assumed that the pixels are square, so in theory the value might not be 100% accurate.


    height : int

    Screen height in pixels. This value changes based on orientation, i.e. in portrait mode height is larger than width and in landscape mode vice versa.

    See also displayHeight.


    rotation : int

    The rotation angle of the (logical content of the) screen, measured anti-clockwise relative to the native orientation of the device. If the rotation is zero it means that the screen is in the native orientation of the device.

    The value is always non-negative. The actual possible values may depend on hardware.

    See also displayWidth and displayHeight.


    width : int

    Screen width in pixels. This value changes based on orientation, i.e. in portrait mode width is smaller than height and in landscape mode vice versa.

    See also displayWidth.