The QGraphicsTextItem class provides a text item that you can add to a QGraphicsScene 以顯示格式化文本。 更多...
| 頭: | #include <QGraphicsTextItem> |
| qmake: | QT += widgets |
| Since: | Qt 4.2 |
| 繼承: | QGraphicsObject |
| enum | anonymous { Type } |
| QGraphicsTextItem (QGraphicsItem * parent = nullptr) | |
| QGraphicsTextItem (const QString & text , QGraphicsItem * parent = nullptr) | |
| virtual | ~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 override |
| virtual bool | contains (const QPointF & point ) const override |
| virtual bool | isObscuredBy (const QGraphicsItem * item ) const override |
| virtual QPainterPath | opaqueArea () const override |
| virtual void | paint (QPainter * painter , const QStyleOptionGraphicsItem * option , QWidget * widget ) override |
| virtual QPainterPath | shape () const override |
| virtual int | type () const override |
| void | linkActivated (const QString & link ) |
| void | linkHovered (const QString & link ) |
| const QMetaObject | staticMetaObject |
| virtual void | contextMenuEvent (QGraphicsSceneContextMenuEvent * event ) override |
| virtual void | dragEnterEvent (QGraphicsSceneDragDropEvent * event ) override |
| virtual void | dragLeaveEvent (QGraphicsSceneDragDropEvent * event ) override |
| virtual void | dragMoveEvent (QGraphicsSceneDragDropEvent * event ) override |
| virtual void | dropEvent (QGraphicsSceneDragDropEvent * event ) override |
| virtual void | focusInEvent (QFocusEvent * event ) override |
| virtual void | focusOutEvent (QFocusEvent * event ) override |
| virtual void | hoverEnterEvent (QGraphicsSceneHoverEvent * event ) override |
| virtual void | hoverLeaveEvent (QGraphicsSceneHoverEvent * event ) override |
| virtual void | hoverMoveEvent (QGraphicsSceneHoverEvent * event ) override |
| virtual void | inputMethodEvent (QInputMethodEvent * event ) override |
| virtual QVariant | inputMethodQuery (Qt::InputMethodQuery query ) const override |
| virtual void | keyPressEvent (QKeyEvent * event ) override |
| virtual void | keyReleaseEvent (QKeyEvent * event ) override |
| virtual void | mouseDoubleClickEvent (QGraphicsSceneMouseEvent * event ) override |
| virtual void | mouseMoveEvent (QGraphicsSceneMouseEvent * event ) override |
| virtual void | mousePressEvent (QGraphicsSceneMouseEvent * event ) override |
| virtual void | mouseReleaseEvent (QGraphicsSceneMouseEvent * event ) override |
| virtual bool | sceneEvent (QEvent * event ) override |
The QGraphicsTextItem class provides a text item that you can add to a QGraphicsScene 以顯示格式化文本。
若隻需要在項中展示純文本,考慮使用 QGraphicsSimpleTextItem 代替。
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 (),和 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 ().
注意: In order to align HTML text in the center, the item's text width must be set. Otherwise, you can call adjustSize () after setting the item's text.
注意: QGraphicsTextItem 接受 懸停事件 by default. You can change this with setAcceptHoverEvents() .
另請參閱 QGraphicsSimpleTextItem , QGraphicsPathItem , QGraphicsRectItem , QGraphicsEllipseItem , QGraphicsPixmapItem , QGraphicsPolygonItem , QGraphicsLineItem ,和 圖形視圖框架 .
值的返迴是通過虛擬 type () 函數。
| 常量 | 值 | 描述 |
|---|---|---|
QGraphicsTextItem::Type
|
8
|
A graphics text item |
指定是否 QGraphicsTextItem 應自動打開鏈接使用 QDesktopServices::openUrl () 而不是發射 linkActivated 信號。
默認值為 false。
訪問函數:
| 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.
訪問函數:
| QTextCursor | textCursor () const |
| void | setTextCursor (const QTextCursor & cursor ) |
構造 QGraphicsTextItem . parent 被傳遞給 QGraphicsItem 的構造函數。
另請參閱 QGraphicsScene::addItem ().
構造 QGraphicsTextItem ,使用 text 作為默認純文本。 parent 被傳遞給 QGraphicsItem 的構造函數。
另請參閱 QGraphicsScene::addItem ().
[虛擬]
QGraphicsTextItem::
~QGraphicsTextItem
()
銷毀 QGraphicsTextItem .
Adjusts the text item to a reasonable size.
[override virtual]
QRectF
QGraphicsTextItem::
boundingRect
() const
重實現自 QGraphicsItem::boundingRect ().
[override virtual]
bool
QGraphicsTextItem::
contains
(const
QPointF
&
point
) const
重實現自 QGraphicsItem::contains ().
[override virtual protected]
void
QGraphicsTextItem::
contextMenuEvent
(
QGraphicsSceneContextMenuEvent
*
event
)
重實現自 QGraphicsItem::contextMenuEvent ().
Returns the default text color that is used for unformatted text.
另請參閱 setDefaultTextColor ().
返迴項的文本文檔。
另請參閱 setDocument ().
[override virtual protected]
void
QGraphicsTextItem::
dragEnterEvent
(
QGraphicsSceneDragDropEvent
*
event
)
重實現自 QGraphicsItem::dragEnterEvent ().
[override virtual protected]
void
QGraphicsTextItem::
dragLeaveEvent
(
QGraphicsSceneDragDropEvent
*
event
)
重實現自 QGraphicsItem::dragLeaveEvent ().
[override virtual protected]
void
QGraphicsTextItem::
dragMoveEvent
(
QGraphicsSceneDragDropEvent
*
event
)
重實現自 QGraphicsItem::dragMoveEvent ().
[override virtual protected]
void
QGraphicsTextItem::
dropEvent
(
QGraphicsSceneDragDropEvent
*
event
)
重實現自 QGraphicsItem::dropEvent ().
[override virtual protected]
void
QGraphicsTextItem::
focusInEvent
(
QFocusEvent
*
event
)
重實現自 QGraphicsItem::focusInEvent ().
[override virtual protected]
void
QGraphicsTextItem::
focusOutEvent
(
QFocusEvent
*
event
)
重實現自 QGraphicsItem::focusOutEvent ().
Returns the item's font, which is used to render the text.
另請參閱 setFont ().
[override virtual protected]
void
QGraphicsTextItem::
hoverEnterEvent
(
QGraphicsSceneHoverEvent
*
event
)
重實現自 QGraphicsItem::hoverEnterEvent ().
[override virtual protected]
void
QGraphicsTextItem::
hoverLeaveEvent
(
QGraphicsSceneHoverEvent
*
event
)
重實現自 QGraphicsItem::hoverLeaveEvent ().
[override virtual protected]
void
QGraphicsTextItem::
hoverMoveEvent
(
QGraphicsSceneHoverEvent
*
event
)
重實現自 QGraphicsItem::hoverMoveEvent ().
[override virtual protected]
void
QGraphicsTextItem::
inputMethodEvent
(
QInputMethodEvent
*
event
)
重實現自 QGraphicsItem::inputMethodEvent ().
[override virtual protected]
QVariant
QGraphicsTextItem::
inputMethodQuery
(
Qt::InputMethodQuery
query
) const
重實現自 QGraphicsItem::inputMethodQuery ().
[override virtual]
bool
QGraphicsTextItem::
isObscuredBy
(const
QGraphicsItem
*
item
) const
重實現自 QGraphicsItem::isObscuredBy ().
[override virtual protected]
void
QGraphicsTextItem::
keyPressEvent
(
QKeyEvent
*
event
)
重實現自 QGraphicsItem::keyPressEvent ().
[override virtual protected]
void
QGraphicsTextItem::
keyReleaseEvent
(
QKeyEvent
*
event
)
重實現自 QGraphicsItem::keyReleaseEvent ().
[signal]
void
QGraphicsTextItem::
linkActivated
(const
QString
&
link
)
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.
另請參閱 setTextInteractionFlags ().
[signal]
void
QGraphicsTextItem::
linkHovered
(const
QString
&
link
)
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.
另請參閱 setTextInteractionFlags ().
[override virtual protected]
void
QGraphicsTextItem::
mouseDoubleClickEvent
(
QGraphicsSceneMouseEvent
*
event
)
重實現自 QGraphicsItem::mouseDoubleClickEvent ().
[override virtual protected]
void
QGraphicsTextItem::
mouseMoveEvent
(
QGraphicsSceneMouseEvent
*
event
)
重實現自 QGraphicsItem::mouseMoveEvent ().
[override virtual protected]
void
QGraphicsTextItem::
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
)
重實現自 QGraphicsItem::mousePressEvent ().
[override virtual protected]
void
QGraphicsTextItem::
mouseReleaseEvent
(
QGraphicsSceneMouseEvent
*
event
)
重實現自 QGraphicsItem::mouseReleaseEvent ().
[override virtual]
QPainterPath
QGraphicsTextItem::
opaqueArea
() const
重實現自 QGraphicsItem::opaqueArea ().
[override virtual]
void
QGraphicsTextItem::
paint
(
QPainter
*
painter
, const
QStyleOptionGraphicsItem
*
option
,
QWidget
*
widget
)
重實現自 QGraphicsItem::paint ().
[override virtual protected]
bool
QGraphicsTextItem::
sceneEvent
(
QEvent
*
event
)
重實現自 QGraphicsItem::sceneEvent ().
Sets the color for unformatted text to col .
另請參閱 defaultTextColor ().
Sets the text document document on the item.
另請參閱 document ().
Sets the font used to render the text item to font .
另請參閱 font ().
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.
另請參閱 toHtml (), hasFocus (),和 QGraphicsSimpleTextItem .
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.
若 b 為 true, Tab key will cause the widget to change focus; otherwise, the tab key will insert a tab into the document.
在某些場閤,文本編輯不應該允許用戶輸入 Tab (製錶符) 或改變縮進使用 Tab 鍵,因為這會打斷聚焦鏈。默認為 false。
該函數在 Qt 4.5 引入。
另請參閱 tabChangesFocus (), ItemIsFocusable ,和 textInteractionFlags ().
Sets the flags flags to specify how the text item should react to user input.
The default for a QGraphicsTextItem is Qt::NoTextInteraction . This function also affects the ItemIsFocusable QGraphicsItem flag by setting it if flags is different from Qt::NoTextInteraction and clearing it otherwise.
By default, the text is read-only. To transform the item into an editor, set the Qt::TextEditable 標誌。
另請參閱 textInteractionFlags ().
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.
若 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.
默認值為 -1。
注意, QGraphicsTextItem keeps a QTextDocument internally, which is used to calculate the text width.
另請參閱 textWidth () 和 QTextDocument::setTextWidth ().
[override virtual]
QPainterPath
QGraphicsTextItem::
shape
() const
重實現自 QGraphicsItem::shape ().
返迴
true
若
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.
該函數在 Qt 4.5 引入。
另請參閱 setTabChangesFocus ().
Returns the current text interaction flags.
另請參閱 setTextInteractionFlags ().
Returns the text width.
The width is calculated with the QTextDocument that QGraphicsTextItem keeps internally.
另請參閱 setTextWidth () 和 QTextDocument::textWidth ().
Returns the item's text converted to HTML, or an empty QString if no text has been set.
另請參閱 setHtml ().
Returns the item's text converted to plain text, or an empty QString if no text has been set.
另請參閱 setPlainText ().
[override virtual]
int
QGraphicsTextItem::
type
() const
重實現自 QGraphicsItem::type ().