Qt QML Type

Provides a global object with useful enums and functions from Qt. More...

Import Statement: import QtQml 2.3

Properties

Detailed Description

The Qt object is a global object with utility functions, properties and enums.

It is not instantiable; to use it, call the members of the global Qt object directly. For example:

import QtQuick 2.0

Text {
    color: Qt.rgba(1, 0, 0, 1)
    text: Qt.md5("hello, world")
}

Enums

The Qt object contains the enums available in the Qt Namespace. For example, you can access the Qt::LeftButton and Qt::RightButton enumeration values as Qt.LeftButton and Qt.RightButton.

Types

The Qt object also contains helper functions for creating objects of specific data types. This is primarily useful when setting the properties of an item when the property has one of the following types:

  • rect - use Qt.rect()
  • point - use Qt.point()
  • size - use Qt.size()

If the QtQuick module has been imported, the following helper functions for creating objects of specific data types are also available for clients to use:

  • color - use Qt.rgba(), Qt.hsla(), Qt.darker(), Qt.lighter() or Qt.tint()
  • font - use Qt.font()
  • vector2d - use Qt.vector2d()
  • vector3d - use Qt.vector3d()
  • vector4d - use Qt.vector4d()
  • quaternion - use Qt.quaternion()
  • matrix4x4 - use Qt.matrix4x4()

There are also string based constructors for these types. See QML Basic Types for more information.

Date/Time Formatters

The Qt object contains several functions for formatting QDateTime, QDate and QTime values.

  • string Qt.formatDateTime(datetime date, variant format)
  • string Qt.formatDate(datetime date, variant format)
  • string Qt.formatTime(datetime date, variant format)

The format specification is described at Qt.formatDateTime.

Dynamic Object Creation

The following functions on the global object allow you to dynamically create QML items from files or strings. See Dynamic QML Object Creation from JavaScript for an overview of their use.

  • object Qt.createComponent(url)
  • object Qt.createQmlObject(string qml, object parent, string filepath)

Other Functions

The following functions are also on the Qt object.

  • Qt.quit()
  • Qt.md5(string)
  • string Qt.btoa(string)
  • string Qt.atob(string)
  • object Qt.binding(function)
  • object Qt.locale()
  • string Qt.resolvedUrl(string)
  • Qt.openUrlExternally(string)
  • list<string> Qt.fontFamilies()

Property Documentation

[since 5.1] application : object

The application object provides access to global application state properties shared by many QML components.

It is the same as the Application singleton.

The following example uses the application object to indicate whether the application is currently active:

import QtQuick 2.0

Rectangle {
    width: 300; height: 55
    color: Qt.application.active ? "white" : "lightgray"
    Text {
        text: "Application " + (Qt.application.active ? "active" : "inactive")
        opacity: Qt.application.active ? 1.0 : 0.5
        anchors.centerIn: parent
    }
}

Note: When using QML without a QGuiApplication, the following properties will be undefined:

  • application.active
  • application.state
  • application.layoutDirection
  • application.font

This property was introduced in Qt 5.1.


[since 5.0] inputMethod : object

The inputMethod object allows access to application's QInputMethod object and all its properties and slots. See the QInputMethod documentation for further details.

This property was introduced in Qt 5.0.


[since 5.1] platform : object

The platform object provides info about the underlying platform.

Its properties are:

platform.osThis read-only property contains the name of the operating system.

Possible values are:

  • "android" - Android
  • "ios" - iOS
  • "tvos" - tvOS
  • "linux" - Linux
  • "osx" - macOS
  • "qnx" - QNX (since Qt 5.9.3)
  • "unix" - Other Unix-based OS
  • "windows" - Windows
  • "wasm" - WebAssembly
platform.pluginNameThis is the name of the platform set on the QGuiApplication instance as returned by QGuiApplication::platformName()

This property was introduced in Qt 5.1.


[since 5.5] styleHints : object

The styleHints object provides platform-specific style hints and settings. See the QStyleHints documentation for further details.

Note: The styleHints object is only available when using the Qt Quick module.

The following example uses the styleHints object to determine whether an item should gain focus on mouse press or touch release:

import QtQuick 2.4

MouseArea {
    id: button

    onPressed: {
        if (!Qt.styleHints.setFocusOnTouchRelease)
            button.forceActiveFocus()
    }
    onReleased: {
        if (Qt.styleHints.setFocusOnTouchRelease)
            button.forceActiveFocus()
    }
}

This property was introduced in Qt 5.5.


[since 5.15] uiLanguage : string

The uiLanguage holds the name of the language to be used for user interface string translations. It is exposed in C++ as QQmlEngine::uiLanguage property.

You can set the value freely and use it in bindings. It is recommended to set it after installing translators in your application. By convention, an empty string means no translation from the language used in the source code is intended to occur.

If you're using QQmlApplicationEngine and the value changes, QQmlEngine::retranslate() will be called.

This property was introduced in Qt 5.15.


© 2021 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.