QGraphicsTextItemclass provides a text item that you can add to aQGraphicsScene以显示格式化文本。 更多 …
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
()
def
setExtension
(extension, variant)
def
supportsExtension
(extension)
def
linkActivated
(arg__1)
def
linkHovered
(arg__1)
若只需要在项中展示纯文本,请考虑使用
QGraphicsSimpleTextItem代替。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(),和contains(). 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().注意
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.![]()
注意
QGraphicsTextItemacceptshover eventsby default. You can change this withsetAcceptHoverEvents().
QGraphicsTextItem
(
[
parent=None
]
)
¶
QGraphicsTextItem(text[, parent=None])
- param parent
- param text
unicode
构造
QGraphicsTextItem
.
parent
会被传递给
QGraphicsItem
‘s constructor.
另请参阅
构造
QGraphicsTextItem
,使用
text
作为默认纯文本。
parent
会被传递给
QGraphicsItem
‘s constructor.
另请参阅
PySide2.QtWidgets.QGraphicsTextItem.
adjustSize
(
)
¶
Adjusts the text item to a reasonable size.
PySide2.QtWidgets.QGraphicsTextItem.
defaultTextColor
(
)
¶
QColor
Returns the default text color that is used for unformatted text.
PySide2.QtWidgets.QGraphicsTextItem.
document
(
)
¶
QTextDocument
Returns the item’s text document.
另请参阅
PySide2.QtWidgets.QGraphicsTextItem.
font
(
)
¶
QFont
Returns the item’s font, which is used to render the text.
另请参阅
PySide2.QtWidgets.QGraphicsTextItem.
linkActivated
(
arg__1
)
¶
arg__1 – unicode
PySide2.QtWidgets.QGraphicsTextItem.
linkHovered
(
arg__1
)
¶
arg__1 – unicode
PySide2.QtWidgets.QGraphicsTextItem.
openExternalLinks
(
)
¶
bool
PySide2.QtWidgets.QGraphicsTextItem.
setDefaultTextColor
(
c
)
¶
c
–
QColor
Sets the color for unformatted text to
col
.
另请参阅
PySide2.QtWidgets.QGraphicsTextItem.
setDocument
(
document
)
¶
document
–
QTextDocument
Sets the text document
document
on the item.
另请参阅
PySide2.QtWidgets.QGraphicsTextItem.
setExtension
(
extension
,
variant
)
¶
extension
–
Extension
variant – object
PySide2.QtWidgets.QGraphicsTextItem.
setFont
(
font
)
¶
font
–
QFont
Sets the font used to render the text item to
font
.
另请参阅
PySide2.QtWidgets.QGraphicsTextItem.
setHtml
(
html
)
¶
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
ensureVisible()
to ensure that the text is visible in all viewports.
另请参阅
toHtml()
hasFocus()
QGraphicsSimpleTextItem
PySide2.QtWidgets.QGraphicsTextItem.
setOpenExternalLinks
(
open
)
¶
open
–
bool
另请参阅
PySide2.QtWidgets.QGraphicsTextItem.
setPlainText
(
text
)
¶
text – unicode
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.
另请参阅
toHtml()
hasFocus()
PySide2.QtWidgets.QGraphicsTextItem.
setTabChangesFocus
(
b
)
¶
b
–
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.
另请参阅
tabChangesFocus()
ItemIsFocusable
textInteractionFlags()
PySide2.QtWidgets.QGraphicsTextItem.
setTextCursor
(
cursor
)
¶
cursor
–
QTextCursor
另请参阅
PySide2.QtWidgets.QGraphicsTextItem.
setTextInteractionFlags
(
flags
)
¶
flags
–
TextInteractionFlags
Sets the flags
flags
to specify how the text item should react to user input.
The default for a
QGraphicsTextItem
is
NoTextInteraction
. This function also affects the
ItemIsFocusable
QGraphicsItem
flag by setting it if
flags
is different from
NoTextInteraction
and clearing it otherwise.
By default, the text is read-only. To transform the item into an editor, set the
TextEditable
标志。
PySide2.QtWidgets.QGraphicsTextItem.
setTextWidth
(
width
)
¶
width
–
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。
注意:
QGraphicsTextItem
keeps a
QTextDocument
internally, which is used to calculate the text width.
另请参阅
textWidth()
setTextWidth()
PySide2.QtWidgets.QGraphicsTextItem.
supportsExtension
(
extension
)
¶
extension
–
Extension
bool
PySide2.QtWidgets.QGraphicsTextItem.
tabChangesFocus
(
)
¶
bool
返回
true
if 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.
另请参阅
PySide2.QtWidgets.QGraphicsTextItem.
textCursor
(
)
¶
QTextCursor
另请参阅
PySide2.QtWidgets.QGraphicsTextItem.
textInteractionFlags
(
)
¶
TextInteractionFlags
Returns the current text interaction flags.
PySide2.QtWidgets.QGraphicsTextItem.
textWidth
(
)
¶
qreal
Returns the text width.
The width is calculated with the
QTextDocument
that
QGraphicsTextItem
keeps internally.
另请参阅
setTextWidth()
textWidth()
PySide2.QtWidgets.QGraphicsTextItem.
toHtml
(
)
¶
unicode
Returns the item’s text converted to HTML, or an empty
QString
if no text has been set.
另请参阅
PySide2.QtWidgets.QGraphicsTextItem.
toPlainText
(
)
¶
unicode
Returns the item’s text converted to plain text, or an empty
QString
if no text has been set.
另请参阅