C

Qt Quick Ultralite font_bindings Example

/****************************************************************************** ** ** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Quick Ultralite module. ** ** $QT_BEGIN_LICENSE:COMM$ ** ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see http://www.qt.io/terms-conditions. For further ** information use the contact form at http://www.qt.io/contact-us. ** ** $QT_END_LICENSE$ ** ******************************************************************************/
import QtQuick 2.15 import QtQuick.Controls 2.15 Rectangle { // The Fontmap used by this example has defined the following // font class names: // // "Roboto" // "Roboto Light" // "Roboto Italic" // // QUL_DEFAULT_FONT_FAMILY is set to "Roboto" Flickable { anchors.fill: parent contentHeight: appLayout.height contentWidth: appLayout.width interactive: true Column { id: appLayout Switch { id: italicSwitch text: "Italic style" } Slider { id: pixelSizeSlider from: 24 to: 100 } Text { text: "Hello world" // Depending on the 'italicSwitch.checked' value, the font class // name can be "Roboto" or "Roboto Italic". font.italic: italicSwitch.checked font.pixelSize: pixelSizeSlider.value } Text { text: "from Qt." // An alternativele way is to provide a full class name via font.family property. font.family: italicSwitch.checked ? "Roboto Italic" : "Roboto" font.pixelSize: pixelSizeSlider.value } Switch { id: lightSwitch text: "Extra light style" } Text { id: lightText text: "This text is displayed" font.pixelSize: pixelSizeSlider.value // Depending on the 'lightSwitch.checked' value, the font class // name can be "Roboto" or "Roboto Light". font.weight: lightSwitch.checked ? Font.Light : Font.Normal } Text { // To save the memory resources, the font configurations can be shared // between elements. This happens automatically in the emitted cpp code // when font configuration uses only constant values in font.* bindings. font: lightText.font text: "using the Monotype Spark font engine." } } } }