Home · All Namespaces · All Classes · Main Classes · Grouped Classes · Modules · Functions

QGraphicsTextItem Class Reference
[QtGui module]

The QGraphicsTextItem class provides a text item that you can add to a QGraphicsScene to display formatted text. More...

 #include <QGraphicsTextItem>

Inherits QObject and QGraphicsItem.

This class was introduced in Qt 4.2.

Properties

Public Functions

Signals

Additional Inherited Members


Detailed Description

The QGraphicsTextItem class provides a text item that you can add to a QGraphicsScene to display formatted text.

If you only need to show plain text in an item, consider using QGraphicsSimpleTextItem instead.

To set the item's text, pass a QString to QGraphicsTextItem's constructor, or call setHtml()/setPlainText().

QGraphicsTextItem uses the text's formatted size and the associated font to provide a reasonable implementation of boundingRect(), shape(), and contains(). You can set the font by calling setFont().

It is possible to make the item editable by setting the Qt::TextEditorInteraction flag using setTextInteractionFlags().

The item's preferred text width can be set using setTextWidth() and obtained using textWidth().

Note: In order to align HTML text in the center, the item's text width must be set.

Note: QGraphicsTextItem accepts hover events by default. You can change this with setAcceptHoverEvents().

See also QGraphicsSimpleTextItem, QGraphicsPathItem, QGraphicsRectItem, QGraphicsEllipseItem, QGraphicsPixmapItem, QGraphicsPolygonItem, QGraphicsLineItem, and The Graphics View Framework.


Property Documentation

openExternalLinks : bool

Specifies whether QGraphicsTextItem should automatically open links using QDesktopServices::openUrl() instead of emitting the linkActivated signal.

The default value is false.

Access functions:

textCursor : QTextCursor

This property represents the visible text cursor in an editable text item.

By default, if the item's text has not been set, this property contains a null text cursor; otherwise it contains a text cursor placed at the start of the item's document.

Access functions:


Member Function Documentation

QGraphicsTextItem::QGraphicsTextItem ( QGraphicsItem * parent = 0 )

Constructs a QGraphicsTextItem. parent is passed to QGraphicsItem's constructor.

See also QGraphicsScene::addItem().

QGraphicsTextItem::QGraphicsTextItem ( const QString & text, QGraphicsItem * parent = 0 )

Constructs a QGraphicsTextItem, using text as the default plain text. parent is passed to QGraphicsItem's constructor.

See also QGraphicsScene::addItem().

QGraphicsTextItem::~QGraphicsTextItem ()

Destroys the QGraphicsTextItem.

void QGraphicsTextItem::adjustSize ()

Adjusts the text item to a reasonable size.

QColor QGraphicsTextItem::defaultTextColor () const

Returns the default text color that is used to for unformatted text.

See also setDefaultTextColor().

QTextDocument * QGraphicsTextItem::document () const

Returns the item's text document.

See also setDocument().

QFont QGraphicsTextItem::font () const

Returns the item's font, which is used to render the text.

See also setFont().

void QGraphicsTextItem::linkActivated ( const QString & link )   [signal]

This signal is emitted when the user clicks on a link on a text item that enables Qt::LinksAccessibleByMouse or Qt::LinksAccessibleByKeyboard. link is the link that was clicked.

See also setTextInteractionFlags().

void QGraphicsTextItem::linkHovered ( const QString & link )   [signal]

This signal is emitted when the user hovers over a link on a text item that enables Qt::LinksAccessibleByMouse. link is the link that was hovered over.

See also setTextInteractionFlags().

void QGraphicsTextItem::setDefaultTextColor ( const QColor & col )

Sets the color for unformatted text to col.

See also defaultTextColor().

void QGraphicsTextItem::setDocument ( QTextDocument * document )

Sets the text document document on the item.

See also document().

void QGraphicsTextItem::setFont ( const QFont & font )

Sets the font used to render the text item to font.

See also font().

void QGraphicsTextItem::setHtml ( const QString & text )

Sets the item's text to text, assuming that text is HTML formatted. If the item has keyboard input focus, this function will also call ensureVisible() to ensure that the text is visible in all viewports.

See also toHtml(), hasFocus(), and QGraphicsSimpleTextItem.

void QGraphicsTextItem::setPlainText ( const QString & text )

Sets the item's text to text. If the item has keyboard input focus, this function will also call ensureVisible() to ensure that the text is visible in all viewports.

See also toHtml() and hasFocus().

void QGraphicsTextItem::setTabChangesFocus ( bool b )

If b is true, the Tab key will cause the widget to change focus; otherwise, the tab key will insert a tab into the document.

In some occasions text edits should not allow the user to input tabulators or change indentation using the Tab key, as this breaks the focus chain. The default is false.

This function was introduced in Qt 4.5.

See also tabChangesFocus(), ItemIsFocusable, and textInteractionFlags().

void QGraphicsTextItem::setTextInteractionFlags ( Qt::TextInteractionFlags flags )

Sets the flags flags to specify how the text item should react to user input.

The default for a QGraphicsTextItem is Qt::NoTextInteraction. Setting a value different to Qt::NoTextInteraction will also set the ItemIsFocusable QGraphicsItem flag.

By default, the text is read-only. To transform the item into an editor, set the Qt::TextEditable flag.

See also textInteractionFlags().

void QGraphicsTextItem::setTextWidth ( qreal width )

Sets the preferred width for the item's text. If the actual text is wider than the specified width then it will be broken into multiple lines.

If width is set to -1 then the text will not be broken into multiple lines unless it is enforced through an explicit line break or a new paragraph.

The default value is -1.

Note that QGraphicsTextItem keeps a QTextDocument internally, which is used to calculate the text width.

See also textWidth() and QTextDocument::setTextWidth().

bool QGraphicsTextItem::tabChangesFocus () const

Returns true if the Tab key will cause the widget to change focus; otherwise, false is returned.

By default, this behavior is disabled, and this function will return false.

This function was introduced in Qt 4.5.

See also setTabChangesFocus().

Qt::TextInteractionFlags QGraphicsTextItem::textInteractionFlags () const

Returns the current text interaction flags.

See also setTextInteractionFlags().

qreal QGraphicsTextItem::textWidth () const

Returns the text width.

The width is calculated with the QTextDocument that QGraphicsTextItem keeps internally.

See also setTextWidth() and QTextDocument::textWidth().

QString QGraphicsTextItem::toHtml () const

Returns the item's text converted to HTML, or an empty QString if no text has been set.

See also setHtml().

QString QGraphicsTextItem::toPlainText () const

Returns the item's text converted to plain text, or an empty QString if no text has been set.

See also setPlainText().


Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies) Trademarks
Qt 4.5.1