Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

QTextFormat Class Reference
[QtGui module]

The QTextFormat class provides formatting information for a QTextDocument. More...

#include <QTextFormat>

Inherited by QTextBlockFormat, QTextCharFormat, QTextFrameFormat, and QTextListFormat.

Public Types

  • enum FormatType { InvalidFormat, BlockFormat, CharFormat, ListFormat, ..., UserFormat }
  • enum ObjectTypes { NoObject, ImageObject, TableObject }
  • enum Property { ObjectIndex, CssFloat, LayoutDirection, OutlinePen, ..., UserProperty }

Public Functions


Detailed Description

The QTextFormat class provides formatting information for a QTextDocument.

A QTextFormat is a generic class used for describing the format of parts of a QTextDocument. The derived classes QTextCharFormat, QTextBlockFormat, QTextListFormat, and QTextTableFormat are usually more useful, and describe the formatting that is applied to specific parts of the document.

A format has a FormatType which specifies the kinds of thing 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 by type(), and the format can be tested with isCharFormat(), isBlockFormat(), isListFormat(), isTableFormat(), isFrameFormat(), and isImageFormat(). If the type is determined, it can be retrieved with toCharFormat(), toBlockFormat(), toListFormat(), toTableFormat(), toFrameFormat(), and toImageFormat().

A format's properties can be set with the setProperty() functions, and retrieved with boolProperty(), intProperty(), doubleProperty(), and stringProperty() as appropriate. All the property IDs used in the format can be retrieved with allPropertyIds(). One format can be merged into another using merge().

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

See also Text Related Classes.


Member Type Documentation

enum QTextFormat::FormatType

ConstantValue
QTextFormat::InvalidFormat-1
QTextFormat::BlockFormat1
QTextFormat::CharFormat2
QTextFormat::ListFormat3
QTextFormat::TableFormat4
QTextFormat::FrameFormat5
QTextFormat::UserFormat100

enum QTextFormat::ObjectTypes

ConstantValue
QTextFormat::NoObject0
QTextFormat::ImageObject1
QTextFormat::TableObject2

enum QTextFormat::Property

ConstantValue
QTextFormat::ObjectIndex0x0

Paragraph and character properties

ConstantValueDescription
QTextFormat::CssFloat0x0800 
QTextFormat::LayoutDirection0x0801The layout direction of the text in the document (Qt::LayoutDirection).
QTextFormat::OutlinePen0x810 
QTextFormat::ForegroundBrush0x821 
QTextFormat::BackgroundBrush0x820 

Paragraph properties

ConstantValue
QTextFormat::BlockAlignment0x1010
QTextFormat::BlockTopMargin0x1030
QTextFormat::BlockBottomMargin0x1031
QTextFormat::BlockLeftMargin0x1032
QTextFormat::BlockRightMargin0x1033
QTextFormat::TextIndent0x1034
QTextFormat::BlockIndent0x1040
QTextFormat::BlockNonBreakableLines0x1050
QTextFormat::BlockTrailingHorizontalRulerWidth0x1060

Character properties

ConstantValue
QTextFormat::FontFamily0x2000
QTextFormat::FontPointSize0x2001
QTextFormat::FontSizeAdjustment0x2002
QTextFormat::FontWeight0x2003
QTextFormat::FontItalic0x2004
QTextFormat::FontUnderline0x2005
QTextFormat::FontOverline0x2006
QTextFormat::FontStrikeOut0x2007
QTextFormat::FontFixedPitch0x2008
QTextFormat::TextUnderlineColor0x2010
QTextFormat::TextVerticalAlignment0x2021
QTextFormat::IsAnchor0x2030
QTextFormat::AnchorHref0x2031
QTextFormat::AnchorName0x2032
QTextFormat::ObjectType0x2f00

List properties

ConstantValue
QTextFormat::ListStyle0x3000
QTextFormat::ListIndent0x3001

Table and frame properties

ConstantValue
QTextFormat::TableColumns0x4100
QTextFormat::FrameBorder0x4000
QTextFormat::FrameMargin0x4001
QTextFormat::FramePadding0x4002
QTextFormat::FrameWidth0x4003
QTextFormat::FrameHeight0x4004
QTextFormat::TableColumnWidthConstraints0x4101
QTextFormat::TableCellSpacing0x4102
QTextFormat::TableCellPadding0x4103

Table cell properties

ConstantValue
QTextFormat::TableCellRowSpan0x4810
QTextFormat::TableCellColumnSpan0x4811

Image properties

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

Member Function Documentation

QTextFormat::QTextFormat ()

Creates a new text format with an InvalidFormat.

See also FormatType.

QTextFormat::QTextFormat ( int type )

Creates a new text format of the given type.

See also FormatType.

QTextFormat::QTextFormat ( const QTextFormat & other )

Creates a new text format with the same attributes at the other text format.

QTextFormat::~QTextFormat ()

Destroys this text format.

QBrush QTextFormat::background () const

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

See also setBackground(), clearBackground(), and foreground().

bool QTextFormat::boolProperty ( int propertyId ) const

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

See also setProperty(), intProperty(), doubleProperty(), stringProperty(), colorProperty(), lengthProperty(), lengthVectorProperty(), and Property.

QBrush QTextFormat::brushProperty ( int propertyId ) const

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

See also setProperty(), boolProperty(), intProperty(), doubleProperty(), stringProperty(), lengthProperty(), lengthVectorProperty(), and Property.

void QTextFormat::clearBackground ()

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

See also background(), setBackground(), and clearForeground().

void QTextFormat::clearForeground ()

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

See also foreground(), setForeground(), and clearBackground().

void QTextFormat::clearProperty ( int propertyId )

Clears the value of the property given by propertyId

QColor QTextFormat::colorProperty ( int propertyId ) const

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

See also setProperty(), boolProperty(), intProperty(), doubleProperty(), stringProperty(), lengthProperty(), lengthVectorProperty(), and Property.

qreal QTextFormat::doubleProperty ( int propertyId ) const

Returns the value of the property specified by propertyId. If the property isn't of QVariant::Double type, 0 is returned instead.

See also setProperty(), boolProperty(), intProperty(), stringProperty(), colorProperty(), lengthProperty(), lengthVectorProperty(), and Property.

QBrush QTextFormat::foreground () const

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

See also setForeground(), clearForeground(), and background().

bool QTextFormat::hasProperty ( int propertyId ) const

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

See also properties() and Property.

int QTextFormat::intProperty ( int propertyId ) const

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

See also setProperty(), boolProperty(), doubleProperty(), stringProperty(), colorProperty(), lengthProperty(), lengthVectorProperty(), and Property.

bool QTextFormat::isBlockFormat () const

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

bool QTextFormat::isCharFormat () const

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

bool QTextFormat::isFrameFormat () const

Returns true if this text format is a FrameFormat; 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 a ListFormat; otherwise returns false.

bool QTextFormat::isTableFormat () const

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

bool QTextFormat::isValid () const

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

Qt::LayoutDirection QTextFormat::layoutDirection () const

Returns the document's layout direction.

See also setLayoutDirection().

QTextLength QTextFormat::lengthProperty ( int propertyId ) const

Returns the value of the property given by propertyId.

See also setProperty(), boolProperty(), intProperty(), doubleProperty(), stringProperty(), colorProperty(), lengthVectorProperty(), and Property.

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

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

See also setProperty(), boolProperty(), intProperty(), doubleProperty(), stringProperty(), colorProperty(), lengthProperty(), and Property.

void QTextFormat::merge ( const QTextFormat & other )

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

int QTextFormat::objectIndex () const

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

See also setObjectIndex().

int QTextFormat::objectType () const

Returns the text format's object type. See ObjectTypes.

See also setObjectType().

QPen QTextFormat::penProperty ( int propertyId ) const

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

See also setProperty(), boolProperty(), intProperty(), doubleProperty(), stringProperty(), lengthProperty(), lengthVectorProperty(), and Property.

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 given propertyId.

See also setProperty().

void QTextFormat::setBackground ( const QBrush & brush )

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

See also background(), clearBackground(), and setForeground().

void QTextFormat::setForeground ( const QBrush & brush )

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

See also foreground(), clearForeground(), and setBackground().

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

Sets the document's layout direction to the specified direction.

See also layoutDirection().

void QTextFormat::setObjectIndex ( int index )

Sets the format object's object index.

See also objectIndex().

void QTextFormat::setObjectType ( int type )

Sets the text format's object type. See ObjectTypes.

See also objectType().

void QTextFormat::setProperty ( int propertyId, const QVariant & value )

Sets the property specified by the propertyId to the given value.

See also property().

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

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Sets the value of the property given by propertyId to value.

See also lengthVectorProperty() and Property.

QString QTextFormat::stringProperty ( int propertyId ) const

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

See also setProperty(), boolProperty(), intProperty(), doubleProperty(), colorProperty(), lengthProperty(), lengthVectorProperty(), and Property.

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.

QTextTableFormat QTextFormat::toTableFormat () const

Returns this format as a table format.

int QTextFormat::type () const

Returns the type of this format.

See also ObjectTypes.

QTextFormat::operator QVariant () const

Returns the text format as a QVariant

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

Returns true if this text format is different from the other text format.

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

Assigns the other text format to this text format, and returns a reference to this text format.

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

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

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année

Le Qt Developer Network au hasard

Logo

Utiliser QML et QtWebKit avec PySide

Le Qt Developer Network est un réseau de développeurs Qt anglophone, où ils peuvent partager leur expérience sur le framework. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.0
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web