QTextCharFormat#
The QTextCharFormat
class provides formatting information for characters in a QTextDocument
. More…
Inherited by: QTextTableCellFormat, QTextImageFormat
Synopsis#
Functions#
def
anchorHref
()def
anchorNames
()def
baselineOffset
()def
font
()def
fontCapitalization
()def
fontFamilies
()def
fontFamily
()def
fontFixedPitch
()def
fontHintingPreference
()def
fontItalic
()def
fontKerning
()def
fontLetterSpacing
()def
fontLetterSpacingType
()def
fontOverline
()def
fontPointSize
()def
fontStretch
()def
fontStrikeOut
()def
fontStyleHint
()def
fontStyleName
()def
fontStyleStrategy
()def
fontUnderline
()def
fontWeight
()def
fontWordSpacing
()def
isAnchor
()def
setAnchor
(anchor)def
setAnchorHref
(value)def
setAnchorNames
(names)def
setBaselineOffset
(baseline)def
setFont
(font[, behavior=QTextCharFormat.FontPropertiesInheritanceBehavior.FontPropertiesAll])def
setFontCapitalization
(capitalization)def
setFontFamilies
(families)def
setFontFamily
(family)def
setFontFixedPitch
(fixedPitch)def
setFontHintingPreference
(hintingPreference)def
setFontItalic
(italic)def
setFontKerning
(enable)def
setFontLetterSpacing
(spacing)def
setFontLetterSpacingType
(letterSpacingType)def
setFontOverline
(overline)def
setFontPointSize
(size)def
setFontStretch
(factor)def
setFontStrikeOut
(strikeOut)def
setFontStyleHint
(hint[, strategy=QFont.PreferDefault])def
setFontStyleName
(styleName)def
setFontStyleStrategy
(strategy)def
setFontUnderline
(underline)def
setFontWeight
(weight)def
setFontWordSpacing
(spacing)def
setSubScriptBaseline
(baseline)def
setSuperScriptBaseline
(baseline)def
setTableCellColumnSpan
(tableCellColumnSpan)def
setTableCellRowSpan
(tableCellRowSpan)def
setTextOutline
(pen)def
setToolTip
(tip)def
setUnderlineColor
(color)def
setUnderlineStyle
(style)def
setVerticalAlignment
(alignment)def
subScriptBaseline
()def
superScriptBaseline
()def
tableCellColumnSpan
()def
tableCellRowSpan
()def
textOutline
()def
toolTip
()def
underlineColor
()def
underlineStyle
()def
verticalAlignment
()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description#
The character format of text in a document specifies the visual properties of the text, as well as information about its role in a hypertext document.
The font used can be set by supplying a font to the setFont()
function, and each aspect of its appearance can be adjusted to give the desired effect. setFontFamilies()
and setFontPointSize()
define the font’s family (e.g. Times) and printed size; setFontWeight()
and setFontItalic()
provide control over the style of the font. setFontUnderline()
, setFontOverline()
, setFontStrikeOut()
, and setFontFixedPitch()
provide additional effects for text.
The color is set with setForeground()
. If the text is intended to be used as an anchor (for hyperlinks), this can be enabled with setAnchor()
. The setAnchorHref()
and setAnchorNames()
functions are used to specify the information about the hyperlink’s destination and the anchor’s name.
- class PySide6.QtGui.QTextCharFormat#
PySide6.QtGui.QTextCharFormat(fmt)
- Parameters:
Constructs a new character format object.
- PySide6.QtGui.QTextCharFormat.VerticalAlignment#
This enum describes the ways that adjacent characters can be vertically aligned.
Constant
Description
QTextCharFormat.AlignNormal
Adjacent characters are positioned in the standard way for text in the writing system in use.
QTextCharFormat.AlignSuperScript
Characters are placed above the base line for normal text.
QTextCharFormat.AlignSubScript
Characters are placed below the base line for normal text.
QTextCharFormat.AlignMiddle
The center of the object is vertically aligned with the base line. Currently, this is only implemented for inline objects.
QTextCharFormat.AlignBottom
The bottom edge of the object is vertically aligned with the base line.
QTextCharFormat.AlignTop
The top edge of the object is vertically aligned with the base line.
QTextCharFormat.AlignBaseline
The base lines of the characters are aligned.
- PySide6.QtGui.QTextCharFormat.UnderlineStyle#
This enum describes the different ways drawing underlined text.
Constant
Description
QTextCharFormat.NoUnderline
Text is draw without any underlining decoration.
QTextCharFormat.SingleUnderline
A line is drawn using Qt::SolidLine.
QTextCharFormat.DashUnderline
Dashes are drawn using Qt::DashLine.
QTextCharFormat.DotLine
Dots are drawn using Qt::DotLine;
QTextCharFormat.DashDotLine
Dashes and dots are drawn using Qt::DashDotLine.
QTextCharFormat.DashDotDotLine
Underlines draw drawn using Qt::DashDotDotLine.
QTextCharFormat.WaveUnderline
The text is underlined using a wave shaped line.
QTextCharFormat.SpellCheckUnderline
The underline is drawn depending on the SpellCheckUnderlineStyle theme hint of QPlatformTheme. By default this is mapped to WaveUnderline, on macOS it is mapped to DotLine.
See also
PenStyle
- PySide6.QtGui.QTextCharFormat.FontPropertiesInheritanceBehavior#
This enum specifies how the setFont()
function should behave with respect to unset font properties.
Constant
Description
QTextCharFormat.FontPropertiesSpecifiedOnly
If a property is not explicitly set, do not change the text format’s property value.
QTextCharFormat.FontPropertiesAll
If a property is not explicitly set, override the text format’s property with a default value.
See also
- PySide6.QtGui.QTextCharFormat.anchorHref()#
- Return type:
str
Returns the text format’s hypertext link, or an empty string if none has been set.
See also
- PySide6.QtGui.QTextCharFormat.anchorNames()#
- Return type:
list of strings
Returns the anchor names associated with this text format, or an empty string list if none has been set. If the anchor names are set, text with this format can be the destination of a hypertext link.
See also
- PySide6.QtGui.QTextCharFormat.baselineOffset()#
- Return type:
float
Returns the the baseline offset in %.
- PySide6.QtGui.QTextCharFormat.font()#
- Return type:
Returns the font for this character format.
See also
- PySide6.QtGui.QTextCharFormat.fontCapitalization()#
- Return type:
Returns the current capitalization type of the font.
See also
- PySide6.QtGui.QTextCharFormat.fontFamilies()#
- Return type:
object
Returns the text format’s font families.
Note
This function returns a QVariant for historical reasons. It will be corrected to return QStringList in Qt 7. The variant contains a QStringList object, which can be extracted by calling toStringList()
on it.
See also
- PySide6.QtGui.QTextCharFormat.fontFamily()#
- Return type:
str
Note
This function is deprecated.
Use fontFamilies()
instead.
Returns the text format’s font family.
See also
- PySide6.QtGui.QTextCharFormat.fontFixedPitch()#
- Return type:
bool
Returns true
if the text format’s font is fixed pitch; otherwise returns false
.
See also
- PySide6.QtGui.QTextCharFormat.fontHintingPreference()#
- Return type:
Returns the hinting preference set for this text format.
- PySide6.QtGui.QTextCharFormat.fontItalic()#
- Return type:
bool
Returns true
if the text format’s font is italic; otherwise returns false
.
See also
- PySide6.QtGui.QTextCharFormat.fontKerning()#
- Return type:
bool
Returns true
if the font kerning is enabled.
See also
- PySide6.QtGui.QTextCharFormat.fontLetterSpacing()#
- Return type:
float
Returns the current letter spacing.
- PySide6.QtGui.QTextCharFormat.fontLetterSpacingType()#
- Return type:
Returns the letter spacing type of this format..
- PySide6.QtGui.QTextCharFormat.fontOverline()#
- Return type:
bool
Returns true
if the text format’s font is overlined; otherwise returns false
.
See also
- PySide6.QtGui.QTextCharFormat.fontPointSize()#
- Return type:
float
Returns the font size used to display text in this format.
See also
- PySide6.QtGui.QTextCharFormat.fontStretch()#
- Return type:
int
Returns the current font stretching.
See also
- PySide6.QtGui.QTextCharFormat.fontStrikeOut()#
- Return type:
bool
Returns true
if the text format’s font is struck out (has a horizontal line drawn through it); otherwise returns false
.
See also
Returns the font style hint.
See also
- PySide6.QtGui.QTextCharFormat.fontStyleName()#
- Return type:
object
Returns the text format’s font style name.
Note
This function returns a QVariant for historical reasons. It will be corrected to return QStringList in Qt 7. The variant contains a QStringList object, which can be extracted by calling toStringList()
on it.
See also
- PySide6.QtGui.QTextCharFormat.fontStyleStrategy()#
- Return type:
Returns the current font style strategy.
See also
- PySide6.QtGui.QTextCharFormat.fontUnderline()#
- Return type:
bool
Returns true
if the text format’s font is underlined; otherwise returns false
.
See also
- PySide6.QtGui.QTextCharFormat.fontWeight()#
- Return type:
int
Returns the text format’s font weight.
See also
setFontWeight()
font()
Weight
- PySide6.QtGui.QTextCharFormat.fontWordSpacing()#
- Return type:
float
Returns the current word spacing value.
See also
- PySide6.QtGui.QTextCharFormat.isAnchor()#
- Return type:
bool
Returns true
if the text is formatted as an anchor; otherwise returns false
.
See also
- PySide6.QtGui.QTextCharFormat.setAnchor(anchor)#
- Parameters:
anchor – bool
If anchor
is true, text with this format represents an anchor, and is formatted in the appropriate way; otherwise the text is formatted normally. (Anchors are hyperlinks which are often shown underlined and in a different color from plain text.)
The way the text is rendered is independent of whether or not the format has a valid anchor defined. Use setAnchorHref()
, and optionally setAnchorNames()
to create a hypertext link.
See also
- PySide6.QtGui.QTextCharFormat.setAnchorHref(value)#
- Parameters:
value – str
Sets the hypertext link for the text format to the given value
. This is typically a URL like “http://example.com/index.html”.
The anchor will be displayed with the value
as its display text; if you want to display different text call setAnchorNames()
.
To format the text as a hypertext link use setAnchor()
.
See also
- PySide6.QtGui.QTextCharFormat.setAnchorNames(names)#
- Parameters:
names – list of strings
Sets the text format’s anchor names
. For the anchor to work as a hyperlink, the destination must be set with setAnchorHref()
and the anchor must be enabled with setAnchor()
.
See also
- PySide6.QtGui.QTextCharFormat.setBaselineOffset(baseline)#
- Parameters:
baseline – float
Sets the base line (in % of height) of text to baseline
. A positive value moves the text up, by the corresponding %; a negative value moves it down. The default value is 0.
- PySide6.QtGui.QTextCharFormat.setFont(font[, behavior=QTextCharFormat.FontPropertiesInheritanceBehavior.FontPropertiesAll])#
- Parameters:
font –
PySide6.QtGui.QFont
behavior –
FontPropertiesInheritanceBehavior
Sets the text format’s font
.
If behavior
is FontPropertiesAll
, the font property that has not been explicitly set is treated like as it were set with default value; If behavior
is FontPropertiesSpecifiedOnly
, the font property that has not been explicitly set is ignored and the respective property value remains unchanged.
See also
- PySide6.QtGui.QTextCharFormat.setFontCapitalization(capitalization)#
- Parameters:
capitalization –
Capitalization
Sets the capitalization of the text that appears in this font to capitalization
.
A font’s capitalization makes the text appear in the selected capitalization mode.
See also
- PySide6.QtGui.QTextCharFormat.setFontFamilies(families)#
- Parameters:
families – list of strings
Sets the text format’s font families
.
See also
- PySide6.QtGui.QTextCharFormat.setFontFamily(family)#
- Parameters:
family – str
Note
This function is deprecated.
Use setFontFamilies()
instead.
Sets the text format’s font family
.
See also
- PySide6.QtGui.QTextCharFormat.setFontFixedPitch(fixedPitch)#
- Parameters:
fixedPitch – bool
If fixedPitch
is true, sets the text format’s font to be fixed pitch; otherwise a non-fixed pitch font is used.
See also
- PySide6.QtGui.QTextCharFormat.setFontHintingPreference(hintingPreference)#
- Parameters:
hintingPreference –
HintingPreference
Sets the hinting preference of the text format’s font to be hintingPreference
.
- PySide6.QtGui.QTextCharFormat.setFontItalic(italic)#
- Parameters:
italic – bool
If italic
is true, sets the text format’s font to be italic; otherwise the font will be non-italic.
See also
- PySide6.QtGui.QTextCharFormat.setFontKerning(enable)#
- Parameters:
enable – bool
Enables kerning for this font if enable
is true; otherwise disables it.
When kerning is enabled, glyph metrics do not add up anymore, even for Latin text. In other words, the assumption that width(‘a’) + width(‘b’) is equal to width(“ab”) is not neccesairly true.
See also
- PySide6.QtGui.QTextCharFormat.setFontLetterSpacing(spacing)#
- Parameters:
spacing – float
Sets the letter spacing of this format to the given spacing
. The meaning of the value depends on the font letter spacing type.
For percentage spacing a value of 100 indicates default spacing; a value of 200 doubles the amount of space a letter takes.
- PySide6.QtGui.QTextCharFormat.setFontLetterSpacingType(letterSpacingType)#
- Parameters:
letterSpacingType –
SpacingType
Sets the letter spacing type of this format to letterSpacingType
.
- PySide6.QtGui.QTextCharFormat.setFontOverline(overline)#
- Parameters:
overline – bool
If overline
is true, sets the text format’s font to be overlined; otherwise the font is displayed non-overlined.
See also
- PySide6.QtGui.QTextCharFormat.setFontPointSize(size)#
- Parameters:
size – float
Sets the text format’s font size
.
See also
- PySide6.QtGui.QTextCharFormat.setFontStretch(factor)#
- Parameters:
factor – int
Sets the stretch factor for the font to factor
.
The stretch factor changes the width of all characters in the font by factor percent. For example, setting factor
to 150 results in all characters in the font being 1.5 times (ie. 150%) wider. The default stretch factor is 100. The minimum stretch factor is 1, and the maximum stretch factor is 4000.
The stretch factor is only applied to outline fonts. The stretch factor is ignored for bitmap fonts.
See also
- PySide6.QtGui.QTextCharFormat.setFontStrikeOut(strikeOut)#
- Parameters:
strikeOut – bool
If strikeOut
is true, sets the text format’s font with strike-out enabled (with a horizontal line through it); otherwise it is displayed without strikeout.
See also
- PySide6.QtGui.QTextCharFormat.setFontStyleHint(hint[, strategy=QFont.PreferDefault])#
- Parameters:
hint –
StyleHint
strategy –
StyleStrategy
Sets the font style hint
and strategy
.
Qt does not support style hints on X11 since this information is not provided by the window system.
See also
- PySide6.QtGui.QTextCharFormat.setFontStyleName(styleName)#
- Parameters:
styleName – str
Sets the text format’s font styleName
.
See also
- PySide6.QtGui.QTextCharFormat.setFontStyleStrategy(strategy)#
- Parameters:
strategy –
StyleStrategy
Sets the font style strategy
.
- PySide6.QtGui.QTextCharFormat.setFontUnderline(underline)#
- Parameters:
underline – bool
If underline
is true, sets the text format’s font to be underlined; otherwise it is displayed non-underlined.
See also
- PySide6.QtGui.QTextCharFormat.setFontWeight(weight)#
- Parameters:
weight – int
Sets the text format’s font weight to weight
.
See also
fontWeight()
setFont()
Weight
- PySide6.QtGui.QTextCharFormat.setFontWordSpacing(spacing)#
- Parameters:
spacing – float
Sets the word spacing of this format to the given spacing
, in pixels.
See also
- PySide6.QtGui.QTextCharFormat.setSubScriptBaseline(baseline)#
- Parameters:
baseline – float
Sets the subscript’s base line as a % of font height to baseline
. The default value is 16.67% (1/6 of height)
- PySide6.QtGui.QTextCharFormat.setSuperScriptBaseline(baseline)#
- Parameters:
baseline – float
Sets the superscript’s base line as a % of font height to baseline
. The default value is 50% (1/2 of height).
- PySide6.QtGui.QTextCharFormat.setTableCellColumnSpan(tableCellColumnSpan)#
- Parameters:
tableCellColumnSpan – int
- PySide6.QtGui.QTextCharFormat.setTableCellRowSpan(tableCellRowSpan)#
- Parameters:
tableCellRowSpan – int
- PySide6.QtGui.QTextCharFormat.setTextOutline(pen)#
- Parameters:
pen –
PySide6.QtGui.QPen
Sets the pen used to draw the outlines of characters to the given pen
.
See also
- PySide6.QtGui.QTextCharFormat.setToolTip(tip)#
- Parameters:
tip – str
Sets the tool tip for a fragment of text to the given text
.
See also
- PySide6.QtGui.QTextCharFormat.setUnderlineColor(color)#
- Parameters:
color –
PySide6.QtGui.QColor
Sets the color used to draw underlines, overlines and strikeouts on the characters with this format to the color
specified.
See also
- PySide6.QtGui.QTextCharFormat.setUnderlineStyle(style)#
- Parameters:
style –
UnderlineStyle
Sets the style of underlining the text to style
.
See also
- PySide6.QtGui.QTextCharFormat.setVerticalAlignment(alignment)#
- Parameters:
alignment –
VerticalAlignment
Sets the vertical alignment used for the characters with this format to the alignment
specified.
See also
- PySide6.QtGui.QTextCharFormat.subScriptBaseline()#
- Return type:
float
Returns the subscript’s base line as a % of font height.
- PySide6.QtGui.QTextCharFormat.superScriptBaseline()#
- Return type:
float
Returns the superscript’s base line as a % of font height.
- PySide6.QtGui.QTextCharFormat.tableCellColumnSpan()#
- Return type:
int
- PySide6.QtGui.QTextCharFormat.tableCellRowSpan()#
- Return type:
int
- PySide6.QtGui.QTextCharFormat.textOutline()#
- Return type:
Returns the pen used to draw the outlines of characters in this format.
See also
- PySide6.QtGui.QTextCharFormat.toolTip()#
- Return type:
str
Returns the tool tip that is displayed for a fragment of text.
See also
- PySide6.QtGui.QTextCharFormat.underlineColor()#
- Return type:
Returns the color used to draw underlines, overlines and strikeouts on the characters with this format.
See also
- PySide6.QtGui.QTextCharFormat.underlineStyle()#
- Return type:
Returns the style of underlining the text.
See also
- PySide6.QtGui.QTextCharFormat.verticalAlignment()#
- Return type:
Returns the vertical alignment used for characters with this format.
See also