PySide.QtGui.QGraphicsTextItem class provides a text item that you can add to a PySide.QtGui.QGraphicsScene 以显示格式化文本。
若只需要在项中展示纯文本,请考虑使用 PySide.QtGui.QGraphicsSimpleTextItem 代替。
To set the item's text, pass a PySide.QtCore.QString to PySide.QtGui.QGraphicsTextItem ‘s constructor, or call PySide.QtGui.QGraphicsTextItem.setHtml() / PySide.QtGui.QGraphicsTextItem.setPlainText() .
PySide.QtGui.QGraphicsTextItem uses the text's formatted size and the associated font to provide a reasonable implementation of PySide.QtGui.QGraphicsTextItem.boundingRect() , PySide.QtGui.QGraphicsTextItem.shape() ,和 PySide.QtGui.QGraphicsTextItem.contains() . You can set the font by calling PySide.QtGui.QGraphicsTextItem.setFont() .
It is possible to make the item editable by setting the Qt.TextEditorInteraction flag using PySide.QtGui.QGraphicsTextItem.setTextInteractionFlags() .
The item's preferred text width can be set using PySide.QtGui.QGraphicsTextItem.setTextWidth() and obtained using PySide.QtGui.QGraphicsTextItem.textWidth() .
注意
In order to align HTML text in the center, the item's text width must be set.
注意
PySide.QtGui.QGraphicsTextItem accepts hover events by default. You can change this with PySide.QtGui.QGraphicsItem.setAcceptHoverEvents() .
| 参数: |
|
|---|
Adjusts the text item to a reasonable size.
| 返回类型: | PySide.QtGui.QColor |
|---|
Returns the default text color that is used to for unformatted text.
| 返回类型: | PySide.QtGui.QTextDocument |
|---|
返回项的文本文档。
| 返回类型: | PySide.QtGui.QFont |
|---|
Returns the item's font, which is used to render the text.
| 参数: | arg__1 – unicode |
|---|
| 参数: | arg__1 – unicode |
|---|
| 返回类型: | PySide.QtCore.bool |
|---|
| 参数: | c – PySide.QtGui.QColor |
|---|
Sets the color for unformatted text to col .
| 参数: | document – PySide.QtGui.QTextDocument |
|---|
Sets the text document document on the item.
| 参数: | font – PySide.QtGui.QFont |
|---|
Sets the font used to render the text item to font .
| 参数: | html – unicode |
|---|
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 PySide.QtGui.QGraphicsItem.ensureVisible() to ensure that the text is visible in all viewports.
| 参数: | open – PySide.QtCore.bool |
|---|
| 参数: | text – unicode |
|---|
Sets the item's text to text . If the item has keyboard input focus, this function will also call PySide.QtGui.QGraphicsItem.ensureVisible() to ensure that the text is visible in all viewports.
| 参数: | b – PySide.QtCore.bool |
|---|
若 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.
| 参数: | cursor – PySide.QtGui.QTextCursor |
|---|
| 参数: | flags – PySide.QtCore.Qt.TextInteractionFlags |
|---|
| 参数: | width – PySide.QtCore.qreal |
|---|
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。
注意: PySide.QtGui.QGraphicsTextItem keeps a PySide.QtGui.QTextDocument internally, which is used to calculate the text width.
| 返回类型: | PySide.QtCore.bool |
|---|
返回 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.
| 返回类型: | PySide.QtGui.QTextCursor |
|---|
| 返回类型: | PySide.QtCore.Qt.TextInteractionFlags |
|---|
Returns the current text interaction flags.
| 返回类型: | PySide.QtCore.qreal |
|---|
Returns the text width.
The width is calculated with the PySide.QtGui.QTextDocument that PySide.QtGui.QGraphicsTextItem keeps internally.
| 返回类型: | unicode |
|---|
Returns the item's text converted to HTML, or an empty PySide.QtCore.QString if no text has been set.
| 返回类型: | unicode |
|---|
Returns the item's text converted to plain text, or an empty PySide.QtCore.QString if no text has been set.