QGraphicsTextItem¶
The
QGraphicsTextItemclass provides a text item that you can add to aQGraphicsSceneto display formatted text. More…

Synopsis¶
Functions¶
def
adjustSize()def
defaultTextColor()def
document()def
font()def
openExternalLinks()def
setDefaultTextColor(c)def
setDocument(document)def
setFont(font)def
setHtml(html)def
setOpenExternalLinks(open)def
setPlainText(text)def
setTabChangesFocus(b)def
setTextCursor(cursor)def
setTextInteractionFlags(flags)def
setTextWidth(width)def
tabChangesFocus()def
textCursor()def
textInteractionFlags()def
textWidth()def
toHtml()def
toPlainText()
Virtual functions¶
def
setExtension(extension, variant)def
supportsExtension(extension)
Signals¶
def
linkActivated(arg__1)def
linkHovered(arg__1)
Detailed Description¶
If you only need to show plain text in an item, consider using
QGraphicsSimpleTextIteminstead.To set the item’s text, pass a
QStringtoQGraphicsTextItem‘s constructor, or callsetHtml()/setPlainText().
QGraphicsTextItemuses 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 the
TextEditorInteractionflag usingsetTextInteractionFlags().The item’s preferred text width can be set using
setTextWidth()and obtained usingtextWidth().Note
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.![]()
Note
QGraphicsTextItemacceptshover eventsby default. You can change this withsetAcceptHoverEvents().
- class PySide2.QtWidgets.QGraphicsTextItem([parent=None])¶
PySide2.QtWidgets.QGraphicsTextItem(text[, parent=None])
- param parent:
- param text:
str
Constructs a
QGraphicsTextItem.parentis passed toQGraphicsItem‘s constructor.See also
Constructs a
QGraphicsTextItem, usingtextas the default plain text.parentis passed toQGraphicsItem‘s constructor.See also
- PySide2.QtWidgets.QGraphicsTextItem.adjustSize()¶
Adjusts the text item to a reasonable size.
- PySide2.QtWidgets.QGraphicsTextItem.defaultTextColor()¶
- Return type:
Returns the default text color that is used for unformatted text.
See also
- PySide2.QtWidgets.QGraphicsTextItem.document()¶
- Return type:
Returns the item’s text document.
See also
- PySide2.QtWidgets.QGraphicsTextItem.font()¶
- Return type:
Returns the item’s font, which is used to render the text.
See also
- PySide2.QtWidgets.QGraphicsTextItem.linkActivated(arg__1)¶
- Parameters:
arg__1 – str
- PySide2.QtWidgets.QGraphicsTextItem.linkHovered(arg__1)¶
- Parameters:
arg__1 – str
- PySide2.QtWidgets.QGraphicsTextItem.openExternalLinks()¶
- Return type:
bool
See also
- PySide2.QtWidgets.QGraphicsTextItem.setDefaultTextColor(c)¶
- Parameters:
c –
PySide2.QtGui.QColor
Sets the color for unformatted text to
col.See also
- PySide2.QtWidgets.QGraphicsTextItem.setDocument(document)¶
- Parameters:
document –
PySide2.QtGui.QTextDocument
Sets the text document
documenton the item.See also
- PySide2.QtWidgets.QGraphicsTextItem.setExtension(extension, variant)¶
- Parameters:
extension –
Extensionvariant – object
- PySide2.QtWidgets.QGraphicsTextItem.setFont(font)¶
- Parameters:
font –
PySide2.QtGui.QFont
Sets the font used to render the text item to
font.See also
- PySide2.QtWidgets.QGraphicsTextItem.setHtml(html)¶
- Parameters:
html – str
Sets the item’s text to
text, 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 also
toHtml()hasFocus()QGraphicsSimpleTextItem
- PySide2.QtWidgets.QGraphicsTextItem.setOpenExternalLinks(open)¶
- Parameters:
open – bool
See also
- PySide2.QtWidgets.QGraphicsTextItem.setPlainText(text)¶
- Parameters:
text – str
Sets the item’s text to
text. If the item has keyboard input focus, this function will also callensureVisible()to ensure that the text is visible in all viewports.See also
toHtml()hasFocus()
- PySide2.QtWidgets.QGraphicsTextItem.setTabChangesFocus(b)¶
- Parameters:
b – bool
If
bis 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.
See also
tabChangesFocus()ItemIsFocusabletextInteractionFlags()
- PySide2.QtWidgets.QGraphicsTextItem.setTextCursor(cursor)¶
- Parameters:
cursor –
PySide2.QtGui.QTextCursor
See also
- PySide2.QtWidgets.QGraphicsTextItem.setTextInteractionFlags(flags)¶
- Parameters:
flags –
TextInteractionFlags
Sets the flags
flagsto specify how the text item should react to user input.The default for a
QGraphicsTextItemisNoTextInteraction. This function also affects theItemIsFocusableQGraphicsItemflag by setting it ifflagsis different fromNoTextInteractionand clearing it otherwise.By default, the text is read-only. To transform the item into an editor, set the
TextEditableflag.See also
- PySide2.QtWidgets.QGraphicsTextItem.setTextWidth(width)¶
- Parameters:
width – float
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
widthis 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
QGraphicsTextItemkeeps aQTextDocumentinternally, which is used to calculate the text width.See also
textWidth()setTextWidth()
- PySide2.QtWidgets.QGraphicsTextItem.supportsExtension(extension)¶
- Parameters:
extension –
Extension- Return type:
bool
- PySide2.QtWidgets.QGraphicsTextItem.tabChangesFocus()¶
- Return type:
bool
Returns
trueif 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.
See also
- PySide2.QtWidgets.QGraphicsTextItem.textCursor()¶
- Return type:
See also
- PySide2.QtWidgets.QGraphicsTextItem.textInteractionFlags()¶
- Return type:
TextInteractionFlags
Returns the current text interaction flags.
See also
- PySide2.QtWidgets.QGraphicsTextItem.textWidth()¶
- Return type:
float
Returns the text width.
The width is calculated with the
QTextDocumentthatQGraphicsTextItemkeeps internally.See also
setTextWidth()textWidth()
- PySide2.QtWidgets.QGraphicsTextItem.toHtml()¶
- Return type:
str
Returns the item’s text converted to HTML, or an empty
QStringif no text has been set.See also
- PySide2.QtWidgets.QGraphicsTextItem.toPlainText()¶
- Return type:
str
Returns the item’s text converted to plain text, or an empty
QStringif no text has been set.See also
© 2022 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 the GNU 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.