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

QGraphicsTextItem Class

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

Properties

Public Functions

QGraphicsTextItem(QGraphicsItem * parent = 0)
QGraphicsTextItem(const QString & text, QGraphicsItem * parent = 0)
~QGraphicsTextItem()
voidadjustSize()
QColordefaultTextColor() const
QTextDocument *document() const
QFontfont() const
boolopenExternalLinks() const
voidsetDefaultTextColor(const QColor & col)
voidsetDocument(QTextDocument * document)
voidsetFont(const QFont & font)
voidsetHtml(const QString & text)
voidsetOpenExternalLinks(bool open)
voidsetPlainText(const QString & text)
voidsetTabChangesFocus(bool b)
voidsetTextCursor(const QTextCursor & cursor)
voidsetTextInteractionFlags(Qt::TextInteractionFlags flags)
voidsetTextWidth(qreal width)
booltabChangesFocus() const
QTextCursortextCursor() const
Qt::TextInteractionFlagstextInteractionFlags() const
qrealtextWidth() const
QStringtoHtml() const
QStringtoPlainText() const

Reimplemented Public Functions

virtual QRectFboundingRect() const
virtual boolcontains(const QPointF & point) const
virtual boolisObscuredBy(const QGraphicsItem * item) const
virtual QPainterPathopaqueArea() const
virtual voidpaint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
virtual QPainterPathshape() const
virtual inttype() const

Signals

voidlinkActivated(const QString & link)
voidlinkHovered(const QString & link)

Reimplemented Protected Functions

virtual voidcontextMenuEvent(QGraphicsSceneContextMenuEvent * event)
virtual voiddragEnterEvent(QGraphicsSceneDragDropEvent * event)
virtual voiddragLeaveEvent(QGraphicsSceneDragDropEvent * event)
virtual voiddragMoveEvent(QGraphicsSceneDragDropEvent * event)
virtual voiddropEvent(QGraphicsSceneDragDropEvent * event)
virtual voidfocusInEvent(QFocusEvent * event)
virtual voidfocusOutEvent(QFocusEvent * event)
virtual voidhoverEnterEvent(QGraphicsSceneHoverEvent * event)
virtual voidhoverLeaveEvent(QGraphicsSceneHoverEvent * event)
virtual voidhoverMoveEvent(QGraphicsSceneHoverEvent * event)
virtual voidinputMethodEvent(QInputMethodEvent * event)
virtual QVariantinputMethodQuery(Qt::InputMethodQuery query) const
virtual voidkeyPressEvent(QKeyEvent * event)
virtual voidkeyReleaseEvent(QKeyEvent * event)
virtual voidmouseDoubleClickEvent(QGraphicsSceneMouseEvent * event)
virtual voidmouseMoveEvent(QGraphicsSceneMouseEvent * event)
virtual voidmousePressEvent(QGraphicsSceneMouseEvent * event)
virtual voidmouseReleaseEvent(QGraphicsSceneMouseEvent * event)
virtual boolsceneEvent(QEvent * event)

Additional Inherited Members

Detailed Description

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.

Property Documentation

openExternalLinks :bool

Specifies whetherQGraphicsTextItem should automatically open links usingQDesktopServices::openUrl() instead of emitting thelinkActivated signal.

The default value is false.

Access functions:

boolopenExternalLinks() const
voidsetOpenExternalLinks(bool open)

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:

QTextCursortextCursor() const
voidsetTextCursor(const QTextCursor & cursor)

Member Function Documentation

QGraphicsTextItem::QGraphicsTextItem(QGraphicsItem * parent = 0)

Constructs aQGraphicsTextItem.parent is passed toQGraphicsItem's constructor.

See alsoQGraphicsScene::addItem().

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

Constructs aQGraphicsTextItem, usingtext as the default plain text.parent is passed toQGraphicsItem's constructor.

See alsoQGraphicsScene::addItem().

QGraphicsTextItem::~QGraphicsTextItem()

Destroys theQGraphicsTextItem.

void QGraphicsTextItem::adjustSize()

Adjusts the text item to a reasonable size.

[virtual]QRectF QGraphicsTextItem::boundingRect() const

Reimplemented fromQGraphicsItem::boundingRect().

[virtual]bool QGraphicsTextItem::contains(constQPointF & point) const

Reimplemented fromQGraphicsItem::contains().

[virtual protected]void QGraphicsTextItem::contextMenuEvent(QGraphicsSceneContextMenuEvent * event)

Reimplemented fromQGraphicsItem::contextMenuEvent().

QColor QGraphicsTextItem::defaultTextColor() const

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

See alsosetDefaultTextColor().

QTextDocument * QGraphicsTextItem::document() const

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().

QFont QGraphicsTextItem::font() const

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) const

Reimplemented fromQGraphicsItem::inputMethodQuery().

[virtual]bool QGraphicsTextItem::isObscuredBy(constQGraphicsItem * item) const

Reimplemented 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() const

Reimplemented 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().

void QGraphicsTextItem::setDefaultTextColor(constQColor & col)

Sets the color for unformatted text tocol.

See alsodefaultTextColor().

void QGraphicsTextItem::setDocument(QTextDocument * document)

Sets the text documentdocument on the item.

See alsodocument().

void QGraphicsTextItem::setFont(constQFont & font)

Sets the font used to render the text item tofont.

See alsofont().

void QGraphicsTextItem::setHtml(constQString & text)

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.

void QGraphicsTextItem::setPlainText(constQString & text)

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().

void QGraphicsTextItem::setTabChangesFocus(bool b)

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().

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

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().

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.

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() const

Reimplemented fromQGraphicsItem::shape().

bool QGraphicsTextItem::tabChangesFocus() const

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().

Qt::TextInteractionFlags QGraphicsTextItem::textInteractionFlags() const

Returns the current text interaction flags.

See alsosetTextInteractionFlags().

qreal QGraphicsTextItem::textWidth() const

Returns the text width.

The width is calculated with theQTextDocument thatQGraphicsTextItem keeps internally.

See alsosetTextWidth() andQTextDocument::textWidth().

QString QGraphicsTextItem::toHtml() const

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

See alsosetHtml().

QString QGraphicsTextItem::toPlainText() const

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

See alsosetPlainText().

[virtual]int QGraphicsTextItem::type() const

Reimplemented 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.


[8]ページ先頭

©2009-2025 Movatter.jp