CopperSpice API  1.9.2
QTextCharFormat Class Reference

The QTextCharFormat class provides formatting information for characters in a QTextDocument. More...

Inheritance diagram for QTextCharFormat:
QTextFormat QTextImageFormat QTextTableCellFormat

Public Types

enum  FontPropertiesInheritanceBehavior
 
enum  UnderlineStyle
 
enum  VerticalAlignment
 
- Public Types inherited from QTextFormat
enum  FormatType
 
enum  ObjectTypes
 
enum  Property
 

Public Methods

 QTextCharFormat ()
 
QString anchorHref () const
 
QString anchorName () const
 
QStringList anchorNames () const
 
QFont font () const
 
QFont::Capitalization fontCapitalization () const
 
QString fontFamily () const
 
bool fontFixedPitch () const
 
QFont::HintingPreference fontHintingPreference () const
 
bool fontItalic () const
 
bool fontKerning () const
 
qreal fontLetterSpacing () const
 
QFont::SpacingType fontLetterSpacingType () const
 
bool fontOverline () const
 
qreal fontPointSize () const
 
int fontStretch () const
 
bool fontStrikeOut () const
 
QFont::StyleHint fontStyleHint () const
 
QFont::StyleStrategy fontStyleStrategy () const
 
bool fontUnderline () const
 
int fontWeight () const
 
qreal fontWordSpacing () const
 
bool isAnchor () const
 
bool isValid () const
 
void setAnchor (bool anchor)
 
void setAnchorHref (const QString &value)
 
void setAnchorName (const QString &name)
 
void setAnchorNames (const QStringList &names)
 
void setFont (const QFont &font)
 
void setFont (const QFont &font, FontPropertiesInheritanceBehavior behavior)
 
void setFontCapitalization (QFont::Capitalization capitalization)
 
void setFontFamily (const QString &family)
 
void setFontFixedPitch (bool fixedPitch)
 
void setFontHintingPreference (QFont::HintingPreference hintingPreference)
 
void setFontItalic (bool italic)
 
void setFontKerning (bool enable)
 
void setFontLetterSpacing (qreal spacing)
 
void setFontLetterSpacingType (QFont::SpacingType letterSpacingType)
 
void setFontOverline (bool overline)
 
void setFontPointSize (qreal size)
 
void setFontStretch (int factor)
 
void setFontStrikeOut (bool strikeOut)
 
void setFontStyleHint (QFont::StyleHint hint, QFont::StyleStrategy strategy=QFont::PreferDefault)
 
void setFontStyleStrategy (QFont::StyleStrategy strategy)
 
void setFontUnderline (bool underline)
 
void setFontWeight (int weight)
 
void setFontWordSpacing (qreal spacing)
 
void setTextOutline (const QPen &pen)
 
void setToolTip (const QString &text)
 
void setUnderlineColor (const QColor &color)
 
void setUnderlineStyle (UnderlineStyle style)
 
void setVerticalAlignment (VerticalAlignment alignment)
 
QPen textOutline () const
 
QString toolTip () const
 
QColor underlineColor () const
 
UnderlineStyle underlineStyle () const
 
VerticalAlignment verticalAlignment () const
 
- Public Methods inherited from QTextFormat
 QTextFormat ()
 
 QTextFormat (const QTextFormat &other)
 
 QTextFormat (int type)
 
 ~QTextFormat ()
 
QBrush background () const
 
bool boolProperty (int propertyId) const
 
QBrush brushProperty (int propertyId) const
 
void clearBackground ()
 
void clearForeground ()
 
void clearProperty (int propertyId)
 
QColor colorProperty (int propertyId) const
 
qreal doubleProperty (int propertyId) const
 
QBrush foreground () const
 
bool hasProperty (int propertyId) const
 
int intProperty (int propertyId) const
 
bool isBlockFormat () const
 
bool isCharFormat () const
 
bool isEmpty () const
 
bool isFrameFormat () const
 
bool isImageFormat () const
 
bool isListFormat () const
 
bool isTableCellFormat () const
 
bool isTableFormat () const
 
bool isValid () const
 
Qt::LayoutDirection layoutDirection () const
 
QTextLength lengthProperty (int propertyId) const
 
QVector< QTextLengthlengthVectorProperty (int propertyId) const
 
void merge (const QTextFormat &other)
 
int objectIndex () const
 
int objectType () const
 
 operator QVariant () const
 
bool operator!= (const QTextFormat &other) const
 
QTextFormat & operator= (const QTextFormat &other)
 
bool operator== (const QTextFormat &other) const
 
QPen penProperty (int propertyId) const
 
QMap< int, QVariantproperties () const
 
QVariant property (int propertyId) const
 
int propertyCount () const
 
void setBackground (const QBrush &brush)
 
void setForeground (const QBrush &brush)
 
void setLayoutDirection (Qt::LayoutDirection direction)
 
void setObjectIndex (int index)
 
void setObjectType (int type)
 
void setProperty (int propertyId, const QVariant &value)
 
void setProperty (int propertyId, const QVector< QTextLength > &value)
 
QString stringProperty (int propertyId) const
 
void swap (QTextFormat &other)
 
QTextBlockFormat toBlockFormat () const
 
QTextCharFormat toCharFormat () const
 
QTextFrameFormat toFrameFormat () const
 
QTextImageFormat toImageFormat () const
 
QTextListFormat toListFormat () const
 
QTextTableCellFormat toTableCellFormat () const
 
QTextTableFormat toTableFormat () const
 
int type () const
 

Friends

class QTextFormat
 

Detailed Description

The QTextCharFormat class provides formatting information for characters in a QTextDocument.

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() method and each aspect of its appearance can be adjusted to give the desired effect. setFontFamily() 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.

See also
QTextFormat, QTextBlockFormat, QTextTableFormat, QTextListFormat

Member Enumeration Documentation

This enum specifies how the setFont() method should behave with respect to unset font properties.

ConstantValueDescription
QTextCharFormat::FontPropertiesSpecifiedOnly 0 If a property is not explicitly set, do not change the text format's property value.
QTextCharFormat::FontPropertiesAll 1 If a property is not explicitly set, override the text format's property with a default value.
See also
setFont()

This enum describes the different ways drawing underlined text.

ConstantValueDescription
QTextCharFormat::NoUnderline0 Text is draw without any underlining decoration.
QTextCharFormat::SingleUnderline1A line is drawn using Qt::SolidLine
QTextCharFormat::DashUnderline2Dashes are drawn using Qt::DashLine
QTextCharFormat::DotLine3Dots are drawn using Qt::DotLine
QTextCharFormat::DashDotLine4 Dashes and dots are drawn using Qt::DashDotLine
QTextCharFormat::DashDotDotLine5 Underlines draw drawn using Qt::DashDotDotLine
QTextCharFormat::WaveUnderline6 The text is underlined using a wave shaped line.
QTextCharFormat::SpellCheckUnderline7 The underline is drawn depending on the QStyle::SH_SpellCeckUnderlineStyle style hint of the QApplication style. By default this is mapped to WaveUnderline, on OS X it is mapped to DashDotLine.
See also
Qt::PenStyle

This enum describes the ways that adjacent characters can be vertically aligned.

ConstantValueDescription
QTextCharFormat::AlignNormal 0 Adjacent characters are positioned in the standard way for text in the writing system in use.
QTextCharFormat::AlignSuperScript 1 Characters are placed above the base line for normal text.
QTextCharFormat::AlignSubScript 2 Characters are placed below the base line for normal text.
QTextCharFormat::AlignMiddle 3 Center of the object is vertically aligned with the base line. Currently only implemented for inline objects.
QTextCharFormat::AlignTop 4 Top edge of the object is vertically aligned with the base line.
QTextCharFormat::AlignBottom 5 Bottom edge of the object is vertically aligned with the base line.
QTextCharFormat::AlignBaseline 6 Base lines of the characters are aligned.

Constructor & Destructor Documentation

QTextCharFormat::QTextCharFormat ( )

Constructs a new character format object.

Method Documentation

QString QTextCharFormat::anchorHref ( ) const
inline

Returns the text format's hypertext link, or an empty string if none has been set.

See also
setAnchorHref()
QString QTextCharFormat::anchorName ( ) const
deprecated
Deprecated:
Use anchorNames() instead.

Returns the anchor name associated with this text format, or an empty string if none has been set. If the anchor name is set, text with this format can be the destination of a hypertext link.

See also
setAnchorName()
QStringList QTextCharFormat::anchorNames ( ) const

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
setAnchorNames()
QFont QTextCharFormat::font ( ) const

Returns the font for this character format.

See also
setFont()
QFont::Capitalization QTextCharFormat::fontCapitalization ( ) const
inline

Returns the current capitalization type of the font.

See also
setFontCapitalization()
QString QTextCharFormat::fontFamily ( ) const
inline

Returns the text format's font family.

See also
setFontFamily(), font()
bool QTextCharFormat::fontFixedPitch ( ) const
inline

Returns true if the text format's font is fixed pitch, otherwise returns false.

See also
setFontFixedPitch(), font()
QFont::HintingPreference QTextCharFormat::fontHintingPreference ( ) const
inline

Returns the hinting preference set for this text format.

See also
setFontHintingPreference(), font(), QFont::hintingPreference()
bool QTextCharFormat::fontItalic ( ) const
inline

Returns true if the text format's font is italic, otherwise returns false.

See also
setFontItalic(), font()
bool QTextCharFormat::fontKerning ( ) const
inline

Returns true if the font kerning is enabled.

See also
setFontKerning(), font()
qreal QTextCharFormat::fontLetterSpacing ( ) const
inline

Returns the current letter spacing percentage.

See also
setFontLetterSpacing()
QFont::SpacingType QTextCharFormat::fontLetterSpacingType ( ) const
inline

Returns the letter spacing type of this format.

See also
setFontLetterSpacingType(), setFontLetterSpacing(), fontLetterSpacing()
bool QTextCharFormat::fontOverline ( ) const
inline

Returns true if the text format's font is overlined, otherwise returns false.

See also
setFontOverline(), font()
qreal QTextCharFormat::fontPointSize ( ) const
inline

Returns the font size used to display text in this format.

See also
setFontPointSize(), font()
int QTextCharFormat::fontStretch ( ) const
inline

Returns the current font stretching.

See also
setFontStretch()
bool QTextCharFormat::fontStrikeOut ( ) const
inline

Returns true if the text format's font is struck out (has a horizontal line drawn through it), otherwise returns false.

See also
setFontStrikeOut(), font()
QFont::StyleHint QTextCharFormat::fontStyleHint ( ) const
inline

Returns the font style hint.

See also
setFontStyleHint(), font()
QFont::StyleStrategy QTextCharFormat::fontStyleStrategy ( ) const
inline

Returns the current font style strategy.

See also
setFontStyleStrategy(), font()
bool QTextCharFormat::fontUnderline ( ) const

Returns true if the text format's font is underlined, otherwise returns false.

See also
setFontUnderline(), font()
int QTextCharFormat::fontWeight ( ) const
inline

Returns the text format's font weight.

See also
setFontWeight(), font(), QFont::Weight
qreal QTextCharFormat::fontWordSpacing ( ) const
inline

Returns the current word spacing value.

See also
setFontWordSpacing()
bool QTextCharFormat::isAnchor ( ) const
inline

Returns true if the text is formatted as an anchor, otherwise returns false.

See also
setAnchor(), setAnchorHref(), setAnchorNames()
bool QTextCharFormat::isValid ( ) const
inline

Returns true if this character format is valid, otherwise returns false.

void QTextCharFormat::setAnchor ( bool  anchor)
inline

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
isAnchor()
void QTextCharFormat::setAnchorHref ( const QString value)
inline

Sets the hypertext link for the text format to the given value. This is typically a URL like "http://example.com/index.html&quot;.

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
anchorHref()
void QTextCharFormat::setAnchorName ( const QString name)
inlinedeprecated
Deprecated:
Use setAnchorNames() instead.

Sets the text format's anchor name. 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
anchorName()
void QTextCharFormat::setAnchorNames ( const QStringList names)
inline

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
anchorNames()
void QTextCharFormat::setFont ( const QFont font)

Sets the text format's font.

See also
font()
void QTextCharFormat::setFont ( const QFont font,
FontPropertiesInheritanceBehavior  behavior 
)

Sets the text format's font.

If behavior is QTextCharFormat::FontPropertiesAll, the font property that has not been explicitly set is treated like as it were set with default value; If behavior is QTextCharFormat::FontPropertiesSpecifiedOnly, the font property that has not been explicitly set is ignored and the respective property value remains unchanged.

See also
font()
void QTextCharFormat::setFontCapitalization ( QFont::Capitalization  capitalization)
inline

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
fontCapitalization()
void QTextCharFormat::setFontFamily ( const QString family)
inline

Sets the text format's font family.

See also
fontFamily(), setFont()
void QTextCharFormat::setFontFixedPitch ( bool  fixedPitch)
inline

If fixedPitch is true, sets the text format's font to be fixed pitch, otherwise a non-fixed pitch font is used.

See also
fontFixedPitch(), setFont()
void QTextCharFormat::setFontHintingPreference ( QFont::HintingPreference  hintingPreference)
inline

Sets the hinting preference of the text format's font to be hintingPreference.

See also
fontHintingPreference(), setFont(), QFont::setHintingPreference()
void QTextCharFormat::setFontItalic ( bool  italic)
inline

If italic is true, sets the text format's font to be italic, otherwise the font will be non-italic.

See also
fontItalic(), setFont()
void QTextCharFormat::setFontKerning ( bool  enable)
inline

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 necessarily true.

See also
fontKerning(), setFont()
void QTextCharFormat::setFontLetterSpacing ( qreal  spacing)
inline

Sets the letter spacing of this format to the given spacing, in percent. A value of 100 indicates default spacing; a value of 200 doubles the amount of space a letter takes.

See also
fontLetterSpacing()
void QTextCharFormat::setFontLetterSpacingType ( QFont::SpacingType  letterSpacingType)
inline

Sets the letter spacing type of this format to letterSpacingType.

See also
fontLetterSpacingType(), setFontLetterSpacing(), fontLetterSpacing()
void QTextCharFormat::setFontOverline ( bool  overline)
inline

If overline is true, sets the text format's font to be overlined, otherwise the font is displayed non-overlined.

See also
fontOverline(), setFont()
void QTextCharFormat::setFontPointSize ( qreal  size)
inline

Sets the text format's font size.

See also
fontPointSize(), setFont()
void QTextCharFormat::setFontStretch ( int  factor)
inline

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
fontStretch()
void QTextCharFormat::setFontStrikeOut ( bool  strikeOut)
inline

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
fontStrikeOut(), setFont()
void QTextCharFormat::setFontStyleHint ( QFont::StyleHint  hint,
QFont::StyleStrategy  strategy = QFont::PreferDefault 
)
inline

Sets the font style hint and strategy.

CopperSpice does not support style hints on X11 since this information is not provided by the window system.

See also
fontStyleHint(), setFont(), QFont::setStyleHint()
void QTextCharFormat::setFontStyleStrategy ( QFont::StyleStrategy  strategy)
inline

Sets the font style strategy.

See also
fontStyleStrategy(), setFont(), QFont::setStyleStrategy()
void QTextCharFormat::setFontUnderline ( bool  underline)
inline

If underline is true, sets the text format's font to be underlined, otherwise it is displayed non-underlined.

See also
fontUnderline(), setFont()
void QTextCharFormat::setFontWeight ( int  weight)
inline

Sets the text format's font weight to weight.

See also
fontWeight(), setFont(), QFont::Weight
void QTextCharFormat::setFontWordSpacing ( qreal  spacing)
inline

Sets the word spacing of this format to the given spacing, in pixels.

See also
fontWordSpacing()
void QTextCharFormat::setTextOutline ( const QPen pen)
inline

Sets the pen used to draw the outlines of characters to the given pen.

See also
textOutline()
void QTextCharFormat::setToolTip ( const QString text)
inline

Sets the tool tip for a fragment of text to the given text.

See also
toolTip()
void QTextCharFormat::setUnderlineColor ( const QColor color)
inline

Sets the underline color used for the characters with this format to the color specified.

See also
underlineColor()
void QTextCharFormat::setUnderlineStyle ( UnderlineStyle  style)

Sets the style of underlining the text to style.

See also
underlineStyle()
void QTextCharFormat::setVerticalAlignment ( VerticalAlignment  alignment)
inline

Sets the vertical alignment used for the characters with this format to the alignment specified.

See also
verticalAlignment()
QPen QTextCharFormat::textOutline ( ) const
inline

Returns the pen used to draw the outlines of characters in this format.

See also
setTextOutline()
QString QTextCharFormat::toolTip ( ) const
inline

Returns the tool tip that is displayed for a fragment of text.

See also
setToolTip()
QColor QTextCharFormat::underlineColor ( ) const
inline

Returns the color used to underline the characters with this format.

See also
setUnderlineColor()
UnderlineStyle QTextCharFormat::underlineStyle ( ) const
inline

Returns the style of underlining the text.

See also
setUnderlineStyle()
VerticalAlignment QTextCharFormat::verticalAlignment ( ) const
inline

Returns the vertical alignment used for characters with this format.

See also
setVerticalAlignment()