
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQGraphicsTextItem class provides a text item that you can add to aQGraphicsScene to display formatted text.More...
| Header: | #include <QGraphicsTextItem> |
| Since: | Qt 4.2 |
| Inherits: | QGraphicsObject |
| QGraphicsTextItem(QGraphicsItem * parent = 0) | |
| QGraphicsTextItem(const QString & text, QGraphicsItem * parent = 0) | |
| ~QGraphicsTextItem() | |
| void | adjustSize() |
| QColor | defaultTextColor() const |
| QTextDocument * | document() const |
| QFont | font() const |
| bool | openExternalLinks() const |
| void | setDefaultTextColor(const QColor & col) |
| void | setDocument(QTextDocument * document) |
| void | setFont(const QFont & font) |
| void | setHtml(const QString & text) |
| void | setOpenExternalLinks(bool open) |
| void | setPlainText(const QString & text) |
| void | setTabChangesFocus(bool b) |
| void | setTextCursor(const QTextCursor & cursor) |
| void | setTextInteractionFlags(Qt::TextInteractionFlags flags) |
| void | setTextWidth(qreal width) |
| bool | tabChangesFocus() const |
| QTextCursor | textCursor() const |
| Qt::TextInteractionFlags | textInteractionFlags() const |
| qreal | textWidth() const |
| QString | toHtml() const |
| QString | toPlainText() const |
| virtual QRectF | boundingRect() const |
| virtual bool | contains(const QPointF & point) const |
| virtual bool | isObscuredBy(const QGraphicsItem * item) const |
| virtual QPainterPath | opaqueArea() const |
| virtual void | paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) |
| virtual QPainterPath | shape() const |
| virtual int | type() const |
| void | linkActivated(const QString & link) |
| void | linkHovered(const QString & link) |
| virtual void | contextMenuEvent(QGraphicsSceneContextMenuEvent * event) |
| virtual void | dragEnterEvent(QGraphicsSceneDragDropEvent * event) |
| virtual void | dragLeaveEvent(QGraphicsSceneDragDropEvent * event) |
| virtual void | dragMoveEvent(QGraphicsSceneDragDropEvent * event) |
| virtual void | dropEvent(QGraphicsSceneDragDropEvent * event) |
| virtual void | focusInEvent(QFocusEvent * event) |
| virtual void | focusOutEvent(QFocusEvent * event) |
| virtual void | hoverEnterEvent(QGraphicsSceneHoverEvent * event) |
| virtual void | hoverLeaveEvent(QGraphicsSceneHoverEvent * event) |
| virtual void | hoverMoveEvent(QGraphicsSceneHoverEvent * event) |
| virtual void | inputMethodEvent(QInputMethodEvent * event) |
| virtual QVariant | inputMethodQuery(Qt::InputMethodQuery query) const |
| virtual void | keyPressEvent(QKeyEvent * event) |
| virtual void | keyReleaseEvent(QKeyEvent * event) |
| virtual void | mouseDoubleClickEvent(QGraphicsSceneMouseEvent * event) |
| virtual void | mouseMoveEvent(QGraphicsSceneMouseEvent * event) |
| virtual void | mousePressEvent(QGraphicsSceneMouseEvent * event) |
| virtual void | mouseReleaseEvent(QGraphicsSceneMouseEvent * event) |
| virtual bool | sceneEvent(QEvent * event) |
TheQGraphicsTextItem class provides a text item that you can add to aQGraphicsScene to display formatted text.
If you only need to show plain text in an item, consider usingQGraphicsSimpleTextItem instead.
To set the item's text, pass aQString toQGraphicsTextItem's constructor, or callsetHtml()/setPlainText().
QGraphicsTextItem uses the text's formatted size and the associated font to provide a reasonable implementation ofboundingRect(),shape(), andcontains(). You can set the font by callingsetFont().
It is possible to make the item editable by setting theQt::TextEditorInteraction flag usingsetTextInteractionFlags().
The item's preferred text width can be set usingsetTextWidth() and obtained usingtextWidth().
Note:In order to align HTML text in the center, the item's text width must be set.

Note:QGraphicsTextItem acceptshover events by default. You can change this withsetAcceptHoverEvents().
See alsoQGraphicsSimpleTextItem,QGraphicsPathItem,QGraphicsRectItem,QGraphicsEllipseItem,QGraphicsPixmapItem,QGraphicsPolygonItem,QGraphicsLineItem, andGraphics View Framework.
Specifies whetherQGraphicsTextItem should automatically open links usingQDesktopServices::openUrl() instead of emitting thelinkActivated signal.
The default value is false.
Access functions:
| bool | openExternalLinks() const |
| void | setOpenExternalLinks(bool open) |
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:
| QTextCursor | textCursor() const |
| void | setTextCursor(const QTextCursor & cursor) |
Constructs aQGraphicsTextItem.parent is passed toQGraphicsItem's constructor.
See alsoQGraphicsScene::addItem().
Constructs aQGraphicsTextItem, usingtext as the default plain text.parent is passed toQGraphicsItem's constructor.
See alsoQGraphicsScene::addItem().
Destroys theQGraphicsTextItem.
Adjusts the text item to a reasonable size.
[virtual]QRectF QGraphicsTextItem::boundingRect() constReimplemented fromQGraphicsItem::boundingRect().
[virtual]bool QGraphicsTextItem::contains(constQPointF & point) constReimplemented fromQGraphicsItem::contains().
[virtual protected]void QGraphicsTextItem::contextMenuEvent(QGraphicsSceneContextMenuEvent * event)Reimplemented fromQGraphicsItem::contextMenuEvent().
Returns the default text color that is used to for unformatted text.
See alsosetDefaultTextColor().
Returns the item's text document.
See alsosetDocument().
[virtual protected]void QGraphicsTextItem::dragEnterEvent(QGraphicsSceneDragDropEvent * event)Reimplemented fromQGraphicsItem::dragEnterEvent().
[virtual protected]void QGraphicsTextItem::dragLeaveEvent(QGraphicsSceneDragDropEvent * event)Reimplemented fromQGraphicsItem::dragLeaveEvent().
[virtual protected]void QGraphicsTextItem::dragMoveEvent(QGraphicsSceneDragDropEvent * event)Reimplemented fromQGraphicsItem::dragMoveEvent().
[virtual protected]void QGraphicsTextItem::dropEvent(QGraphicsSceneDragDropEvent * event)Reimplemented fromQGraphicsItem::dropEvent().
[virtual protected]void QGraphicsTextItem::focusInEvent(QFocusEvent * event)Reimplemented fromQGraphicsItem::focusInEvent().
[virtual protected]void QGraphicsTextItem::focusOutEvent(QFocusEvent * event)Reimplemented fromQGraphicsItem::focusOutEvent().
Returns the item's font, which is used to render the text.
See alsosetFont().
[virtual protected]void QGraphicsTextItem::hoverEnterEvent(QGraphicsSceneHoverEvent * event)Reimplemented fromQGraphicsItem::hoverEnterEvent().
[virtual protected]void QGraphicsTextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent * event)Reimplemented fromQGraphicsItem::hoverLeaveEvent().
[virtual protected]void QGraphicsTextItem::hoverMoveEvent(QGraphicsSceneHoverEvent * event)Reimplemented fromQGraphicsItem::hoverMoveEvent().
[virtual protected]void QGraphicsTextItem::inputMethodEvent(QInputMethodEvent * event)Reimplemented fromQGraphicsItem::inputMethodEvent().
[virtual protected]QVariant QGraphicsTextItem::inputMethodQuery(Qt::InputMethodQuery query) constReimplemented fromQGraphicsItem::inputMethodQuery().
[virtual]bool QGraphicsTextItem::isObscuredBy(constQGraphicsItem * item) constReimplemented fromQGraphicsItem::isObscuredBy().
[virtual protected]void QGraphicsTextItem::keyPressEvent(QKeyEvent * event)Reimplemented fromQGraphicsItem::keyPressEvent().
[virtual protected]void QGraphicsTextItem::keyReleaseEvent(QKeyEvent * event)Reimplemented fromQGraphicsItem::keyReleaseEvent().
[signal]void QGraphicsTextItem::linkActivated(constQString & link)This signal is emitted when the user clicks on a link on a text item that enablesQt::LinksAccessibleByMouse orQt::LinksAccessibleByKeyboard.link is the link that was clicked.
See alsosetTextInteractionFlags().
[signal]void QGraphicsTextItem::linkHovered(constQString & link)This signal is emitted when the user hovers over a link on a text item that enablesQt::LinksAccessibleByMouse.link is the link that was hovered over.
See alsosetTextInteractionFlags().
[virtual protected]void QGraphicsTextItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent * event)Reimplemented fromQGraphicsItem::mouseDoubleClickEvent().
[virtual protected]void QGraphicsTextItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event)Reimplemented fromQGraphicsItem::mouseMoveEvent().
[virtual protected]void QGraphicsTextItem::mousePressEvent(QGraphicsSceneMouseEvent * event)Reimplemented fromQGraphicsItem::mousePressEvent().
[virtual protected]void QGraphicsTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)Reimplemented fromQGraphicsItem::mouseReleaseEvent().
[virtual]QPainterPath QGraphicsTextItem::opaqueArea() constReimplemented fromQGraphicsItem::opaqueArea().
[virtual]void QGraphicsTextItem::paint(QPainter * painter, constQStyleOptionGraphicsItem * option,QWidget * widget)Reimplemented fromQGraphicsItem::paint().
[virtual protected]bool QGraphicsTextItem::sceneEvent(QEvent * event)Reimplemented fromQGraphicsItem::sceneEvent().
Sets the color for unformatted text tocol.
See alsodefaultTextColor().
Sets the text documentdocument on the item.
See alsodocument().
Sets the font used to render the text item tofont.
See alsofont().
Sets the item's text totext, assuming that text is HTML formatted. If the item has keyboard input focus, this function will also callensureVisible() to ensure that the text is visible in all viewports.
See alsotoHtml(),hasFocus(), andQGraphicsSimpleTextItem.
Sets the item's text totext. If the item has keyboard input focus, this function will also callensureVisible() to ensure that the text is visible in all viewports.
See alsotoHtml() andhasFocus().
Ifb is true, theTab 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 theTab key, as this breaks the focus chain. The default is false.
This function was introduced in Qt 4.5.
See alsotabChangesFocus(),ItemIsFocusable, andtextInteractionFlags().
Sets the flagsflags to specify how the text item should react to user input.
The default for aQGraphicsTextItem isQt::NoTextInteraction. This function also affects theItemIsFocusableQGraphicsItem flag by setting it ifflags is different fromQt::NoTextInteraction and clearing it otherwise.
By default, the text is read-only. To transform the item into an editor, set theQt::TextEditable flag.
See alsotextInteractionFlags().
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.
Ifwidth 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 thatQGraphicsTextItem keeps aQTextDocument internally, which is used to calculate the text width.
See alsotextWidth() andQTextDocument::setTextWidth().
[virtual]QPainterPath QGraphicsTextItem::shape() constReimplemented fromQGraphicsItem::shape().
Returns true if theTab 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 alsosetTabChangesFocus().
Returns the current text interaction flags.
See alsosetTextInteractionFlags().
Returns the text width.
The width is calculated with theQTextDocument thatQGraphicsTextItem keeps internally.
See alsosetTextWidth() andQTextDocument::textWidth().
Returns the item's text converted to HTML, or an emptyQString if no text has been set.
See alsosetHtml().
Returns the item's text converted to plain text, or an emptyQString if no text has been set.
See alsosetPlainText().
[virtual]int QGraphicsTextItem::type() constReimplemented fromQGraphicsItem::type().
© 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.