Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QTextFormat Class

TheQTextFormat class provides formatting information for aQTextDocument.More...

Header:#include <QTextFormat>
Inherited By:

QTextBlockFormat,QTextCharFormat,QTextFrameFormat, andQTextListFormat

Note: All functions in this class arereentrant.

Public Types

enumFormatType { InvalidFormat, BlockFormat, CharFormat, ListFormat, ..., UserFormat }
enumObjectTypes { NoObject, ImageObject, TableObject, TableCellObject, UserObject }
enumPageBreakFlag { PageBreak_Auto, PageBreak_AlwaysBefore, PageBreak_AlwaysAfter }
flagsPageBreakFlags
enumProperty { ObjectIndex, CssFloat, LayoutDirection, OutlinePen, ..., UserProperty }

Public Functions

QTextFormat()
QTextFormat(int type)
QTextFormat(const QTextFormat & other)
~QTextFormat()
QBrushbackground() const
boolboolProperty(int propertyId) const
QBrushbrushProperty(int propertyId) const
voidclearBackground()
voidclearForeground()
voidclearProperty(int propertyId)
QColorcolorProperty(int propertyId) const
qrealdoubleProperty(int propertyId) const
QBrushforeground() const
boolhasProperty(int propertyId) const
intintProperty(int propertyId) const
boolisBlockFormat() const
boolisCharFormat() const
boolisFrameFormat() const
boolisImageFormat() const
boolisListFormat() const
boolisTableCellFormat() const
boolisTableFormat() const
boolisValid() const
Qt::LayoutDirectionlayoutDirection() const
QTextLengthlengthProperty(int propertyId) const
QVector<QTextLength>lengthVectorProperty(int propertyId) const
voidmerge(const QTextFormat & other)
intobjectIndex() const
intobjectType() const
QPenpenProperty(int propertyId) const
QMap<int, QVariant>properties() const
QVariantproperty(int propertyId) const
intpropertyCount() const
voidsetBackground(const QBrush & brush)
voidsetForeground(const QBrush & brush)
voidsetLayoutDirection(Qt::LayoutDirection direction)
voidsetObjectIndex(int index)
voidsetObjectType(int type)
voidsetProperty(int propertyId, const QVariant & value)
voidsetProperty(int propertyId, const QVector<QTextLength> & value)
QStringstringProperty(int propertyId) const
QTextBlockFormattoBlockFormat() const
QTextCharFormattoCharFormat() const
QTextFrameFormattoFrameFormat() const
QTextImageFormattoImageFormat() const
QTextListFormattoListFormat() const
QTextTableCellFormattoTableCellFormat() const
QTextTableFormattoTableFormat() const
inttype() const
operator QVariant() const
booloperator!=(const QTextFormat & other) const
QTextFormat &operator=(const QTextFormat & other)
booloperator==(const QTextFormat & other) const

Detailed Description

TheQTextFormat class provides formatting information for aQTextDocument.

AQTextFormat is a generic class used for describing the format of parts of aQTextDocument. The derived classesQTextCharFormat,QTextBlockFormat,QTextListFormat, andQTextTableFormat are usually more useful, and describe the formatting that is applied to specific parts of the document.

A format has aFormatType which specifies the kinds of text item it can format; e.g. a block of text, a list, a table, etc. A format also has various properties (some specific to particular format types), as described by the Property enum. Every property has a corresponding Property.

The format type is given bytype(), and the format can be tested withisCharFormat(),isBlockFormat(),isListFormat(),isTableFormat(),isFrameFormat(), andisImageFormat(). If the type is determined, it can be retrieved withtoCharFormat(),toBlockFormat(),toListFormat(),toTableFormat(),toFrameFormat(), andtoImageFormat().

A format's properties can be set with thesetProperty() functions, and retrieved withboolProperty(),intProperty(),doubleProperty(), andstringProperty() as appropriate. All the property IDs used in the format can be retrieved with allPropertyIds(). One format can be merged into another usingmerge().

A format's object index can be set withsetObjectIndex(), and retrieved withobjectIndex(). These methods can be used to associate the format with aQTextObject. It is used to represent lists, frames, and tables inside the document.

See alsoRich Text Processing.

Member Type Documentation

enum QTextFormat::FormatType

This enum describes the text item aQTextFormat object is formatting.

ConstantValueDescription
QTextFormat::InvalidFormat-1An invalid format as created by the default constructor
QTextFormat::BlockFormat1The object formats a text block
QTextFormat::CharFormat2The object formats a single character
QTextFormat::ListFormat3The object formats a list
QTextFormat::TableFormat4The object formats a table
QTextFormat::FrameFormat5The object formats a frame
QTextFormat::UserFormat100 

See alsoQTextCharFormat,QTextBlockFormat,QTextListFormat,QTextTableFormat, andtype().

enum QTextFormat::ObjectTypes

This enum describes what kind ofQTextObject this format is associated with.

ConstantValueDescription
QTextFormat::NoObject0 
QTextFormat::ImageObject1 
QTextFormat::TableObject2 
QTextFormat::TableCellObject3 
QTextFormat::UserObject0x1000The first object that can be used for application-specific purposes.

See alsoQTextObject,QTextTable, andQTextObject::format().

enum QTextFormat::PageBreakFlag
flags QTextFormat::PageBreakFlags

This enum describes how page breaking is performed when printing. It maps to the corresponding css properties.

ConstantValueDescription
QTextFormat::PageBreak_Auto0The page break is determined automatically depending on the available space on the current page
QTextFormat::PageBreak_AlwaysBefore0x001The page is always broken before the paragraph/table
QTextFormat::PageBreak_AlwaysAfter0x010A new page is always started after the paragraph/table

This enum was introduced or modified in Qt 4.2.

The PageBreakFlags type is a typedef forQFlags<PageBreakFlag>. It stores an OR combination of PageBreakFlag values.

See alsoQTextBlockFormat::pageBreakPolicy(),QTextFrameFormat::pageBreakPolicy(), andPageBreakPolicy.

enum QTextFormat::Property

This enum describes the different properties a format can have.

ConstantValueDescription
QTextFormat::ObjectIndex0x0The index of the formatted object. SeeobjectIndex().

Paragraph and character properties

ConstantValueDescription
QTextFormat::CssFloat0x0800How a frame is located relative to the surrounding text
QTextFormat::LayoutDirection0x0801The layout direction of the text in the document (Qt::LayoutDirection).
QTextFormat::OutlinePen0x810 
QTextFormat::ForegroundBrush0x821 
QTextFormat::BackgroundBrush0x820 
QTextFormat::BackgroundImageUrl0x823 

Paragraph properties

ConstantValueDescription
QTextFormat::BlockAlignment0x1010 
QTextFormat::BlockTopMargin0x1030 
QTextFormat::BlockBottomMargin0x1031 
QTextFormat::BlockLeftMargin0x1032 
QTextFormat::BlockRightMargin0x1033 
QTextFormat::TextIndent0x1034 
QTextFormat::TabPositions0x1035Specifies the tab positions. The tab positions are structs ofQTextOption::Tab which are stored in aQList (internally, in aQList<QVariant>).
QTextFormat::BlockIndent0x1040 
QTextFormat::LineHeight0x1048 
QTextFormat::LineHeightType0x1049 
QTextFormat::BlockNonBreakableLines0x1050 
QTextFormat::BlockTrailingHorizontalRulerWidth0x1060The width of a horizontal ruler element.

Character properties

ConstantValueDescription
QTextFormat::FontFamily0x2000 
QTextFormat::FontPointSize0x2001 
QTextFormat::FontPixelSize0x2009 
QTextFormat::FontSizeAdjustment0x2002Specifies the change in size given to the fontsize already set using FontPointSize or FontPixelSize.
QTextFormat::FontFixedPitch0x2008 
QTextFormat::FontWeight0x2003 
QTextFormat::FontItalic0x2004 
QTextFormat::FontUnderline0x2005This property has been deprecated. Use QTextFormat::TextUnderlineStyle instead.
QTextFormat::FontOverline0x2006 
QTextFormat::FontStrikeOut0x2007 
QTextFormat::FontCapitalizationFirstFontPropertySpecifies the capitalization type that is to be applied to the text.
QTextFormat::FontLetterSpacing0x1FE1Changes the default spacing between individual letters in the font. The value is specified in percentage, with 100 as the default value.
QTextFormat::FontWordSpacing0x1FE2Changes the default spacing between individual words. A positive value increases the word spacing by the corresponding pixels; a negative value decreases the spacing.
QTextFormat::FontStyleHint0x1FE3Corresponds to theQFont::StyleHint property
QTextFormat::FontStyleStrategy0x1FE4Corresponds to theQFont::StyleStrategy property
QTextFormat::FontKerning0x1FE5Specifies whether the font has kerning turned on.
QTextFormat::FontHintingPreference0x1FE6Controls the use of hinting according to values of theQFont::HintingPreference enum.
QTextFormat::TextUnderlineColor0x2010 
QTextFormat::TextVerticalAlignment0x2021 
QTextFormat::TextOutline0x2022 
QTextFormat::TextUnderlineStyle0x2023 
QTextFormat::TextToolTip0x2024Specifies the (optional) tool tip to be displayed for a fragment of text.
QTextFormat::IsAnchor0x2030 
QTextFormat::AnchorHref0x2031 
QTextFormat::AnchorName0x2032 
QTextFormat::ObjectType0x2f00 

List properties

ConstantValueDescription
QTextFormat::ListStyle0x3000Specifies the style used for the items in a list, described by values of theQTextListFormat::Style enum.
QTextFormat::ListIndent0x3001Specifies the amount of indentation used for a list.
QTextFormat::ListNumberPrefix0x3002Defines the text which is prepended to item numbers in numeric lists.
QTextFormat::ListNumberSuffix0x3003Defines the text which is appended to item numbers in numeric lists.

Table and frame properties

ConstantValueDescription
QTextFormat::FrameBorder0x4000 
QTextFormat::FrameBorderBrush0x4009 
QTextFormat::FrameBorderStyle0x4010See theBorderStyle enum.
QTextFormat::FrameBottomMargin0x4006 
QTextFormat::FrameHeight0x4004 
QTextFormat::FrameLeftMargin0x4007 
QTextFormat::FrameMargin0x4001 
QTextFormat::FramePadding0x4002 
QTextFormat::FrameRightMargin0x4008 
QTextFormat::FrameTopMargin0x4005 
QTextFormat::FrameWidth0x4003 
QTextFormat::TableCellSpacing0x4102 
QTextFormat::TableCellPadding0x4103 
QTextFormat::TableColumns0x4100 
QTextFormat::TableColumnWidthConstraints0x4101 
QTextFormat::TableHeaderRowCount0x4104 

Table cell properties

ConstantValue
QTextFormat::TableCellRowSpan0x4810
QTextFormat::TableCellColumnSpan0x4811
QTextFormat::TableCellLeftPadding0x4814
QTextFormat::TableCellRightPadding0x4815
QTextFormat::TableCellTopPadding0x4812
QTextFormat::TableCellBottomPadding0x4813

Image properties

ConstantValue
QTextFormat::ImageName0x5000
QTextFormat::ImageWidth0x5010
QTextFormat::ImageHeight0x5011

Selection properties

ConstantValueDescription
QTextFormat::FullWidthSelection0x06000When set on the characterFormat of a selection, the whole width of the text will be shown selected.

Page break properties

ConstantValueDescription
QTextFormat::PageBreakPolicy0x7000Specifies how pages are broken. See thePageBreakFlag enum.
QTextFormat::UserProperty0x100000 

See alsoproperty() andsetProperty().

Member Function Documentation

QTextFormat::QTextFormat()

Creates a new text format with anInvalidFormat.

See alsoFormatType.

QTextFormat::QTextFormat(int type)

Creates a new text format of the giventype.

See alsoFormatType.

QTextFormat::QTextFormat(constQTextFormat & other)

Creates a new text format with the same attributes as theother text format.

QTextFormat::~QTextFormat()

Destroys this text format.

QBrush QTextFormat::background() const

Returns the brush used to paint the document's background.

See alsosetBackground(),clearBackground(), andforeground().

bool QTextFormat::boolProperty(int propertyId) const

Returns the value of the property specified bypropertyId. If the property isn't of QTextFormat::Bool type, false is returned instead.

See alsosetProperty(),intProperty(),doubleProperty(),stringProperty(),colorProperty(),lengthProperty(),lengthVectorProperty(), andProperty.

QBrush QTextFormat::brushProperty(int propertyId) const

Returns the value of the property given bypropertyId; if the property isn't ofQVariant::Brush type,Qt::NoBrush is returned instead.

See alsosetProperty(),boolProperty(),intProperty(),doubleProperty(),stringProperty(),lengthProperty(),lengthVectorProperty(), andProperty.

void QTextFormat::clearBackground()

Clears the brush used to paint the document's background. The default brush will be used.

See alsobackground(),setBackground(), andclearForeground().

void QTextFormat::clearForeground()

Clears the brush used to paint the document's foreground. The default brush will be used.

See alsoforeground(),setForeground(), andclearBackground().

void QTextFormat::clearProperty(int propertyId)

Clears the value of the property given bypropertyId

See alsoProperty.

QColor QTextFormat::colorProperty(int propertyId) const

Returns the value of the property given bypropertyId; if the property isn't ofQVariant::Color type, an invalid color is returned instead.

See alsosetProperty(),boolProperty(),intProperty(),doubleProperty(),stringProperty(),lengthProperty(),lengthVectorProperty(), andProperty.

qreal QTextFormat::doubleProperty(int propertyId) const

Returns the value of the property specified bypropertyId. If the property isn't ofQVariant::Double orQMetaType::Float type, 0 is returned instead.

See alsosetProperty(),boolProperty(),intProperty(),stringProperty(),colorProperty(),lengthProperty(),lengthVectorProperty(), andProperty.

QBrush QTextFormat::foreground() const

Returns the brush used to render foreground details, such as text, frame outlines, and table borders.

See alsosetForeground(),clearForeground(), andbackground().

bool QTextFormat::hasProperty(int propertyId) const

Returns true if the text format has a property with the givenpropertyId; otherwise returns false.

See alsoproperties() andProperty.

int QTextFormat::intProperty(int propertyId) const

Returns the value of the property specified bypropertyId. If the property is not of QTextFormat::Integer type, 0 is returned instead.

See alsosetProperty(),boolProperty(),doubleProperty(),stringProperty(),colorProperty(),lengthProperty(),lengthVectorProperty(), andProperty.

bool QTextFormat::isBlockFormat() const

Returns true if this text format is aBlockFormat; otherwise returns false.

bool QTextFormat::isCharFormat() const

Returns true if this text format is aCharFormat; otherwise returns false.

bool QTextFormat::isFrameFormat() const

Returns true if this text format is aFrameFormat; otherwise returns false.

bool QTextFormat::isImageFormat() const

Returns true if this text format is an image format; otherwise returns false.

bool QTextFormat::isListFormat() const

Returns true if this text format is aListFormat; otherwise returns false.

bool QTextFormat::isTableCellFormat() const

Returns true if this text format is aTableCellFormat; otherwise returns false.

This function was introduced in Qt 4.4.

bool QTextFormat::isTableFormat() const

Returns true if this text format is aTableFormat; otherwise returns false.

bool QTextFormat::isValid() const

Returns true if the format is valid (i.e. is notInvalidFormat); otherwise returns false.

Qt::LayoutDirection QTextFormat::layoutDirection() const

Returns the document's layout direction.

See alsosetLayoutDirection().

QTextLength QTextFormat::lengthProperty(int propertyId) const

Returns the value of the property given bypropertyId.

See alsosetProperty(),boolProperty(),intProperty(),doubleProperty(),stringProperty(),colorProperty(),lengthVectorProperty(), andProperty.

QVector<QTextLength> QTextFormat::lengthVectorProperty(int propertyId) const

Returns the value of the property given bypropertyId. If the property isn't of QTextFormat::LengthVector type, an empty length vector is returned instead.

See alsosetProperty(),boolProperty(),intProperty(),doubleProperty(),stringProperty(),colorProperty(),lengthProperty(), andProperty.

void QTextFormat::merge(constQTextFormat & other)

Merges theother format with this format; where there are conflicts theother format takes precedence.

int QTextFormat::objectIndex() const

Returns the index of the format object, or -1 if the format object is invalid.

See alsosetObjectIndex().

int QTextFormat::objectType() const

Returns the text format's object type.

See alsoObjectTypes andsetObjectType().

QPen QTextFormat::penProperty(int propertyId) const

Returns the value of the property given bypropertyId; if the property isn't ofQVariant::Pen type,Qt::NoPen is returned instead.

See alsosetProperty(),boolProperty(),intProperty(),doubleProperty(),stringProperty(),lengthProperty(),lengthVectorProperty(), andProperty.

QMap<int,QVariant> QTextFormat::properties() const

Returns a map with all properties of this text format.

QVariant QTextFormat::property(int propertyId) const

Returns the property specified by the givenpropertyId.

See alsosetProperty() andProperty.

int QTextFormat::propertyCount() const

Returns the number of properties stored in the format.

This function was introduced in Qt 4.3.

void QTextFormat::setBackground(constQBrush & brush)

Sets the brush use to paint the document's background to thebrush specified.

See alsobackground(),clearBackground(), andsetForeground().

void QTextFormat::setForeground(constQBrush & brush)

Sets the foreground brush to the specifiedbrush. The foreground brush is mostly used to render text.

See alsoforeground(),clearForeground(), andsetBackground().

void QTextFormat::setLayoutDirection(Qt::LayoutDirection direction)

Sets the document's layout direction to the specifieddirection.

See alsolayoutDirection().

void QTextFormat::setObjectIndex(int index)

Sets the format object's objectindex.

See alsoobjectIndex().

void QTextFormat::setObjectType(int type)

Sets the text format's object type totype.

See alsoObjectTypes andobjectType().

void QTextFormat::setProperty(int propertyId, constQVariant & value)

Sets the property specified by thepropertyId to the givenvalue.

See alsoproperty() andProperty.

void QTextFormat::setProperty(int propertyId, constQVector<QTextLength> & value)

Sets the value of the property given bypropertyId tovalue.

See alsolengthVectorProperty() andProperty.

QString QTextFormat::stringProperty(int propertyId) const

Returns the value of the property given bypropertyId; if the property isn't ofQVariant::String type, an empty string is returned instead.

See alsosetProperty(),boolProperty(),intProperty(),doubleProperty(),colorProperty(),lengthProperty(),lengthVectorProperty(), andProperty.

QTextBlockFormat QTextFormat::toBlockFormat() const

Returns this format as a block format.

QTextCharFormat QTextFormat::toCharFormat() const

Returns this format as a character format.

QTextFrameFormat QTextFormat::toFrameFormat() const

Returns this format as a frame format.

QTextImageFormat QTextFormat::toImageFormat() const

Returns this format as an image format.

QTextListFormat QTextFormat::toListFormat() const

Returns this format as a list format.

QTextTableCellFormat QTextFormat::toTableCellFormat() const

Returns this format as a table cell format.

This function was introduced in Qt 4.4.

QTextTableFormat QTextFormat::toTableFormat() const

Returns this format as a table format.

int QTextFormat::type() const

Returns the type of this format.

See alsoFormatType.

QTextFormat::operator QVariant() const

Returns the text format as aQVariant

bool QTextFormat::operator!=(constQTextFormat & other) const

Returns true if this text format is different from theother text format.

QTextFormat & QTextFormat::operator=(constQTextFormat & other)

Assigns theother text format to this text format, and returns a reference to this text format.

bool QTextFormat::operator==(constQTextFormat & other) const

Returns true if this text format is the same as theother text format.

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp