PySide6.QtWidgets.QGraphicsTextItem¶
- class QGraphicsTextItem¶
- The - QGraphicsTextItemclass provides a text item that you can add to a- QGraphicsSceneto display formatted text. More…- Synopsis¶- Methods¶- def - __init__()
- def - adjustSize()
- def - document()
- def - font()
- def - setDocument()
- def - setFont()
- def - setHtml()
- def - setPlainText()
- def - setTextCursor()
- def - setTextWidth()
- def - textCursor()
- def - textWidth()
- def - toHtml()
- def - toPlainText()
 - Virtual methods¶- def - setExtension()
 - Signals¶- def - linkActivated()
- def - linkHovered()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶- If you only need to show plain text in an item, consider using - QGraphicsSimpleTextIteminstead.- To set the item’s text, pass a QString to - QGraphicsTextItem‘s constructor, or call- setHtml()/- setPlainText().- QGraphicsTextItemuses the text’s formatted size and the associated font to provide a reasonable implementation of- boundingRect(),- shape(), and- 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().- 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 - QGraphicsTextItemaccepts- hover eventsby default. You can change this with- setAcceptHoverEvents().- __init__([parent=None])¶
- Parameters:
- parent – - QGraphicsItem
 
 - Constructs a - QGraphicsTextItem.- parentis passed to- QGraphicsItem‘s constructor.- See also - __init__(text[, parent=None])
- Parameters:
- text – str 
- parent – - QGraphicsItem
 
 
 - Constructs a - QGraphicsTextItem, using- textas the default plain text.- parentis passed to- QGraphicsItem‘s constructor.- See also - adjustSize()¶
 - Adjusts the text item to a reasonable size. - Returns the default text color that is used for unformatted text. - See also - document()¶
- Return type:
 
 - Returns the item’s text document. - See also - Returns the item’s font, which is used to render the text. - See also - linkActivated(link)¶
- Parameters:
- link – str 
 
 - This signal is emitted when the user clicks on a link on a text item that enables Qt::LinksAccessibleByMouse or Qt::LinksAccessibleByKeyboard. - linkis the link that was clicked.- See also - linkHovered(link)¶
- Parameters:
- link – str 
 
 - This signal is emitted when the user hovers over a link on a text item that enables Qt::LinksAccessibleByMouse. - linkis the link that was hovered over.- See also - openExternalLinks()¶
- Return type:
- bool 
 - See also 
 - Sets the color for unformatted text to - col.- See also - setDocument(document)¶
- Parameters:
- document – - QTextDocument
 
 - Sets the text document - documenton the item.- See also - Sets the font used to render the text item to - font.- See also - 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 call- ensureVisible()to ensure that the text is visible in all viewports.- See also - toHtml()- hasFocus()- QGraphicsSimpleTextItem- setOpenExternalLinks(open)¶
- Parameters:
- open – bool 
 - See also 
 - setPlainText(text)¶
- Parameters:
- text – str 
 
 - 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.- See also - toHtml()- hasFocus()- 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. - setTextCursor(cursor)¶
- Parameters:
- cursor – - QTextCursor
 - See also 
 - setTextInteractionFlags(flags)¶
- Parameters:
- flags – Combination of - TextInteractionFlag
 
 - Sets the flags - flagsto specify how the text item should react to user input.- The default for a - QGraphicsTextItemis Qt::NoTextInteraction. This function also affects the ItemIsFocusable- QGraphicsItemflag by setting it if- flagsis 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 flag. - See also - 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 a QTextDocument internally, which is used to calculate the text width.- See also - 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 - textCursor()¶
- Return type:
 - See also 
 - textInteractionFlags()¶
- Return type:
- Combination of - TextInteractionFlag
 
 - Returns the current text interaction flags. - See also - textWidth()¶
- Return type:
- float 
 
 - Returns the text width. - The width is calculated with the QTextDocument that - QGraphicsTextItemkeeps internally.- See also - toHtml()¶
- Return type:
- str 
 
 - Returns the item’s text converted to HTML, or an empty QString if no text has been set. - See also - toPlainText()¶
- Return type:
- str 
 
 - Returns the item’s text converted to plain text, or an empty QString if no text has been set. - See also