Defines a string in a specified font. 更多...
import 语句: | import QtQuick |
Since: | QtQuick 2.15 |
(从 6.6 起)
(从 6.7 起)
This element defines the shape of a specified string in a specified font. The text's baseline will be translated to the x and y coordinates, and the outlines from the font will be added to the path accordingly.
PathText { x: 0 y: font.pixelSize font.family: "Arial" font.pixelSize: 100 text: "Foobar" }
另请参阅 路径 , QPainterPath::setFillRule , PathPolyline , PathQuad , PathCubic , PathArc , PathAngleArc , PathCurve , PathSvg ,和 PathMove .
font.bold : bool |
Sets whether the font weight is bold.
font.capitalization : enumeration |
Sets the capitalization for the text.
常量 | 描述 |
---|---|
Font.MixedCase
|
no capitalization change is applied |
Font.AllUppercase
|
alters the text to be rendered in all uppercase type |
Font.AllLowercase
|
alters the text to be rendered in all lowercase type |
Font.SmallCaps
|
alters the text to be rendered in small-caps type |
Font.Capitalize
|
alters the text to be rendered with the first character of each word as an uppercase character
PathText { text: "Hello"; font.capitalization: Font.AllLowercase } |
font.family : string |
Sets the family name of the font.
The family name is case insensitive and may optionally include a foundry name, e.g. "Helvetica [Cronyx]". If the family is available from more than one foundry and the foundry isn't specified, an arbitrary foundry is chosen. If the family isn't available a family will be set using the font matching algorithm.
font.features
:
对象
|
Applies integer values to specific OpenType features when shaping the text based on the contents in features . This provides advanced access to the font shaping process, and can be used to support font features that are otherwise not covered in the API.
The font features are represented by a map from four-letter tags to integer values. This integer value passed along with the tag in most cases represents a boolean value: A zero value means the feature is disabled, and a non-zero value means it is enabled. For certain font features, however, it may have other interpretations. For example, when applied to the
salt
feature, the value is an index that specifies the stylistic alternative to use.
例如,
frac
font feature will convert diagonal fractions separated with a slash (such as
1/2
) with a different representation. Typically this will involve baking the full fraction into a single character width (such as
½
).
If a font supports the
frac
feature, then it can be enabled in the shaper as in the following code:
Text { text: "One divided by two is 1/2" font.family: "MyFractionFont" font.features: { "frac": 1 } }
Multiple features can be assigned values in the same mapping. For instance, if you would like to also disable kerning for the font, you can explicitly disable this as follows:
Text { text: "One divided by two is 1/2" font.family: "MyFractionFont" font.features: { "frac": 1, "kern": 0 } }
You can also collect the font properties in an object:
Text { text: "One divided by two is 1/2" font: { family: "MyFractionFont" features: { "frac": 1, "kern": 0 } } }
注意:
By default, Qt will enable and disable certain font features based on other font properties. In particular, the
kern
feature will be enabled/disabled depending on the
font.kerning
特性为
QFont
. In addition, all ligature features (
liga
,
clig
,
dlig
,
hlig
) will be disabled if a
font.letterSpacing
is set, but only for writing systems where the use of ligature is cosmetic. For writing systems where ligatures are required, the features will remain in their default state. The values set using
font.features
will override the default behavior. If, for instance,
"kern"
is set to 1, then kerning will always be enabled, regardless of whether the
font.kerning
property is set to false. Similarly, if it is set to
0
, it will always be disabled.
该特性在 Qt 6.6 引入。
另请参阅 QFont::setFeature ().
font.italic : bool |
Sets whether the font has an italic style.
font.kerning : bool |
Enables or disables the kerning OpenType feature when shaping the text. Disabling this may improve performance when creating or changing the text, at the expense of some cosmetic features. The default value is true.
PathText { text: "OATS FLAVOUR WAY"; font.kerning: false }
font.letterSpacing : real |
Sets the letter spacing for the font.
Letter spacing changes the default spacing between individual letters in the font. A positive value increases the letter spacing by the corresponding pixels; a negative value decreases the spacing.
font.pixelSize : int |
Sets the font size in pixels.
使用此函数使字体设备从属。使用
pointSize
to set the size of the font in a device independent manner.
font.pointSize : real |
Sets the font size in points. The point size must be greater than zero.
font.preferShaping : bool |
Sometimes, a font will apply complex rules to a set of characters in order to display them correctly. In some writing systems, such as Brahmic scripts, this is required in order for the text to be legible, but in e.g. Latin script, it is merely a cosmetic feature. Setting the
preferShaping
property to false will disable all such features when they are not required, which will improve performance in most cases.
默认值为 true。
PathText { text: "Some text"; font.preferShaping: false }
font.strikeout : bool |
Sets whether the font has a strikeout style.
font.styleName : string |
Sets the style name of the font.
The style name is case insensitive. If set, the font will be matched against style name instead of the font properties font.weight , font.bold and font.italic .
font.underline : bool |
Sets whether the text is underlined.
font.variableAxes
:
对象
|
Applies floating point values to variable axes in variable fonts.
Variable fonts provide a way to store multiple variations (with different weights, widths or styles) in the same font file. The variations are given as floating point values for a pre-defined set of parameters, called "variable axes". Specific instances are typically given names by the font designer, and, in Qt, these can be selected using setStyleName() just like traditional sub-families.
In some cases, it is also useful to provide arbitrary values for the different axes. For instance, if a font has a Regular and Bold sub-family, you may want a weight in-between these. You could then manually request this by supplying a custom value for the "wght" axis in the font.
Text { text: "Foobar" font.family: "MyVariableFont" font.variableAxes: { "wght": (Font.Normal + Font.Bold) / 2.0 } }
If the "wght" axis is supported by the font and the given value is within its defined range, a font corresponding to the weight 550.0 will be provided.
There are a few standard axes than many fonts provide, such as "wght" (weight), "wdth" (width), "ital" (italic) and "opsz" (optical size). They each have indivdual ranges defined in the font itself. For instance, "wght" may span from 100 to 900 ( QFont::Thin to QFont::Black ) whereas "ital" can span from 0 to 1 (from not italic to fully italic).
A font may also choose to define custom axes; the only limitation is that the name has to meet the requirements for a QFont::Tag (sequence of four latin-1 characters.)
By default, no variable axes are set.
注意: In order to use variable axes on Windows, the application has to run with either the FreeType or DirectWrite font databases. See the documentation for QGuiApplication::QGuiApplication () for more information on how to select these technologies.
This property was introduced in Qt 6.7.
另请参阅 QFont::setVariableAxis ().
font.weight : int |
Sets the font's weight.
The weight can be one of:
常量 | 描述 |
---|---|
Font.Thin
|
100 |
Font.ExtraLight
|
200 |
Font.Light
|
300 |
Font.Normal
|
400 (default) |
Font.Medium
|
500 |
Font.DemiBold
|
600 |
Font.Bold
|
700 |
Font.ExtraBold
|
800 |
Font.Black
|
900
PathText { text: "Hello"; font.weight: Font.DemiBold } |
font.wordSpacing : real |
Sets the word spacing for the font.
单词间距改变单个单词之间的默认间距。正值按相应像素数量递增单词间距,而负值相应递减单词间间距。
text : string |
The text for which this PathText should contain the outlines.
x : real |
The horizontal position of the PathText 's baseline.
y : real |
The vertical position of the PathText 's baseline.
注意: This property refers to the position of the baseline of the text, not the top of its bounding box. This may cause some confusion, e.g. when using the PathText with Qt Quick Shapes. See FontMetrics for information on how to get the ascent of a font, which can be used to translate the text into the expected position.