Class: QgsFontUtils¶
-
class
qgis.core.
QgsFontUtils
¶ Bases:
sip.wrapper
QgsFontUtils(QgsFontUtils)
Enums
Methods
Adds a font
family
to the list of recently used font families.Returns a CSS string representing the specified font as closely as possible.
Check whether font family on system has specific style
Check whether font family is on system
Check whether font family is on system in a quick manner, which does not compare [foundry]
Check whether exact font is on system
Attempts to parse the provided mime
data
as a QFont.Gets standard test font with specific style
Loads standard test fonts from filesystem or qrc resource
Returns a list of recently used font families.
Sets the properties of a font to match the properties stored in an XML child node.
Sets the properties of a font to match the properties stored in an XML element.
Gets standard test font family
Returns new mime data representing the specified
font
settings.Returns a DOM element containing the properties of the font.
Returns the localized named style of a font, if such a translation is available.
Returns the english named style of a font, if possible.
Updates font with named style and retain all font properties
Signals
Attributes
-
addRecentFontFamily
(family: str)¶ Adds a font
family
to the list of recently used font families.See also
New in version 3.0.
-
asCSS
(font: QFont, pointToPixelMultiplier: float = 1) → str¶ Returns a CSS string representing the specified font as closely as possible.
- Parameters
font – QFont to convert
pointToPixelMultiplier – scaling factor to apply to convert point sizes to pixel font sizes. The CSS returned by this function will always use pixels for font sizes, so this parameter should be set to a suitable value to convert point sizes to pixels (e.g., taking into account destination DPI)
- Returns
partial CSS string, e.g., “font-family: Comic Sans; font-size: 12px;”
New in version 2.16.
-
fontFamilyHasStyle
(family: str, style: str) → bool¶ Check whether font family on system has specific style
- Parameters
family – The family to test
style – The style to test for
- Returns
Whether family has style
New in version 2.1.
-
fontFamilyMatchOnSystem
(family: str, chosen: str = '') → Tuple[bool, bool]¶ Check whether font family is on system
- Parameters
family – The family to test
chosen – The actual family (possibly from different foundry) returned by system
match – Whether the family [foundry] returned by system is a match
- Returns
Whether family was found on system
-
fontFamilyOnSystem
(family: str) → bool¶ Check whether font family is on system in a quick manner, which does not compare [foundry]
- Parameters
family – The family to test
- Returns
Whether family was found on system
Note
This is good for use in loops of large lists, e.g. registering many features for labeling
-
fontMatchOnSystem
(f: QFont) → bool¶ Check whether exact font is on system
- Parameters
f – The font to test for match
-
fromMimeData
(data: QMimeData) → Tuple[QFont, bool]¶ Attempts to parse the provided mime
data
as a QFont. If data can be parsed as a QFont,ok
will be set to true.See also
New in version 3.0.
-
getStandardTestFont
(style: str = '', pointsize: int = 12) → QFont¶ Gets standard test font with specific style
- Parameters
style – Style to load, e.g. Roman, Oblique, Bold, Bold Oblique
pointsize – Font point size to set
- Returns
QFont
New in version 2.1.
-
loadStandardTestFonts
(loadstyles: Iterable[str]) → bool¶ Loads standard test fonts from filesystem or qrc resource
- Parameters
loadstyles – List of styles to load, e.g. All, Roman, Oblique, Bold, Bold Oblique
- Returns
Whether any font was loaded
Note
Done by default on debug app/server startup to ensure fonts available for unit tests (Roman and Bold)
New in version 2.1.
-
recentFontFamilies
() → List[str]¶ Returns a list of recently used font families.
See also
New in version 3.0.
-
setFromXmlChildNode
(font: QFont, element: QDomElement, childNode: str) → bool¶ Sets the properties of a font to match the properties stored in an XML child node. Calling this will overwrite the current properties of the font.
- Parameters
font – font to update
element – DOM element
childNode – name of child node
- Returns
true if child node exists and properties were successfully read from node
See also
See also
New in version 2.10.
-
setFromXmlElement
(font: QFont, element: QDomElement) → bool¶ Sets the properties of a font to match the properties stored in an XML element. Calling this will overwrite the current properties of the font.
- Parameters
font – font to update
element – DOM element
- Returns
true if properties were successfully read from element
See also
See also
New in version 2.10.
-
standardTestFontFamily
() → str¶ Gets standard test font family
New in version 2.1.
-
toMimeData
(font: QFont) → QMimeData¶ Returns new mime data representing the specified
font
settings. Caller takes responsibility for deleting the returned object.See also
New in version 3.0.
-
toXmlElement
(font: QFont, document: QDomDocument, elementName: str) → QDomElement¶ Returns a DOM element containing the properties of the font.
- Parameters
font – font
document – DOM document
elementName – name for DOM element
- Returns
DOM element containing font settings
See also
New in version 2.10.
-
translateNamedStyle
(namedStyle: str) → str¶ Returns the localized named style of a font, if such a translation is available.
- Parameters
namedStyle – a named style, i.e. “Bold”, “Italic”, etc
- Returns
The localized named style
See also
New in version 2.12.
-
untranslateNamedStyle
(namedStyle: str) → str¶ Returns the english named style of a font, if possible.
- Parameters
namedStyle – a localized named style, i.e. “Fett”, “Kursiv”, etc
- Returns
The english named style
See also
New in version 2.12.
-
updateFontViaStyle
(f: QFont, fontstyle: str, fallback: bool = False) → bool¶ Updates font with named style and retain all font properties
- Parameters
f – The font to update
fontstyle – The style to try and switch the font to
fallback – If no matching fontstyle found for font, assign most similar or first style found to font
- Returns
Whether the font was updated (also returns true if the requested style matches font’s current style)
Note
This is a more featured replacement for a Qt 4.8+ function: void QFont.setStyleName ( const QString & styleName )
-