QGraphicsTextItem Class Reference

[ QtGui module]

The QGraphicsTextItem class provides a text item that you can add to a QGraphicsScene to display formatted text. 更多...

继承 QGraphicsObject .

方法

Qt Signals


详细描述

The QGraphicsTextItem class provides a text item that you can add to a QGraphicsScene to display formatted text.

若只需要在项中展示纯文本,请考虑使用 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 () 和 obtained using textWidth ().

注意: In order to align HTML text in the center, the item's text width must be set.

注意: QGraphicsTextItem accepts hover events 在默认情况下。 You can change this with setAcceptHoverEvents() .


方法文档编制

QGraphicsTextItem.__init__ ( self , QGraphicsItem   parent  = None, QGraphicsScene   scene  = None)

parent argument, if not None, causes self to be owned by Qt instead of PyQt.

scene argument, if not None, causes self to be owned by Qt instead of PyQt.

构造 QGraphicsTextItem . parent is passed to QGraphicsItem 's 构造函数。

另请参阅 QGraphicsScene.addItem ().

QGraphicsTextItem.__init__ ( self , QString  text , QGraphicsItem   parent  = None, QGraphicsScene   scene  = None)

parent argument, if not None, causes self to be owned by Qt instead of PyQt.

scene argument, if not None, causes self to be owned by Qt instead of PyQt.

构造 QGraphicsTextItem ,使用 text 作为默认纯文本。 parent 会被传递给 QGraphicsItem 的构造函数。

另请参阅 QGraphicsScene.addItem ().

QGraphicsTextItem.adjustSize ( self )

Adjusts the text item to a reasonable size.

QRectF QGraphicsTextItem.boundingRect ( self )

重实现自 QGraphicsItem.boundingRect ().

bool QGraphicsTextItem.contains ( self , QPointF   point )

重实现自 QGraphicsItem.contains ().

QGraphicsTextItem.contextMenuEvent ( self , QGraphicsSceneContextMenuEvent   event )

重实现自 QGraphicsItem.contextMenuEvent ().

QColor QGraphicsTextItem.defaultTextColor ( self )

Returns the default text color that is used to for unformatted text.

另请参阅 setDefaultTextColor ().

QTextDocument QGraphicsTextItem.document ( self )

返回项的文本文档。

另请参阅 setDocument ().

QGraphicsTextItem.dragEnterEvent ( self , QGraphicsSceneDragDropEvent   event )

重实现自 QGraphicsItem.dragEnterEvent ().

QGraphicsTextItem.dragLeaveEvent ( self , QGraphicsSceneDragDropEvent   event )

重实现自 QGraphicsItem.dragLeaveEvent ().

QGraphicsTextItem.dragMoveEvent ( self , QGraphicsSceneDragDropEvent   event )

重实现自 QGraphicsItem.dragMoveEvent ().

QGraphicsTextItem.dropEvent ( self , QGraphicsSceneDragDropEvent   event )

重实现自 QGraphicsItem.dropEvent ().

QGraphicsTextItem.focusInEvent ( self , QFocusEvent   event )

重实现自 QGraphicsItem.focusInEvent ().

QGraphicsTextItem.focusOutEvent ( self , QFocusEvent   event )

重实现自 QGraphicsItem.focusOutEvent ().

QFont QGraphicsTextItem.font ( self )

Returns the item's font, which is used to render the text.

另请参阅 setFont ().

QGraphicsTextItem.hoverEnterEvent ( self , QGraphicsSceneHoverEvent   event )

重实现自 QGraphicsItem.hoverEnterEvent ().

QGraphicsTextItem.hoverLeaveEvent ( self , QGraphicsSceneHoverEvent   event )

重实现自 QGraphicsItem.hoverLeaveEvent ().

QGraphicsTextItem.hoverMoveEvent ( self , QGraphicsSceneHoverEvent   event )

重实现自 QGraphicsItem.hoverMoveEvent ().

QGraphicsTextItem.inputMethodEvent ( self , QInputMethodEvent   event )

重实现自 QGraphicsItem.inputMethodEvent ().

QVariant QGraphicsTextItem.inputMethodQuery ( self , Qt.InputMethodQuery   query )

重实现自 QGraphicsItem.inputMethodQuery ().

bool QGraphicsTextItem.isObscuredBy ( self , QGraphicsItem   item )

重实现自 QGraphicsItem.isObscuredBy ().

QGraphicsTextItem.keyPressEvent ( self , QKeyEvent   event )

重实现自 QGraphicsItem.keyPressEvent ().

QGraphicsTextItem.keyReleaseEvent ( self , QKeyEvent   event )

重实现自 QGraphicsItem.keyReleaseEvent ().

QGraphicsTextItem.mouseDoubleClickEvent ( self , QGraphicsSceneMouseEvent   event )

重实现自 QGraphicsItem.mouseDoubleClickEvent ().

QGraphicsTextItem.mouseMoveEvent ( self , QGraphicsSceneMouseEvent   event )

重实现自 QGraphicsItem.mouseMoveEvent ().

QGraphicsTextItem.mousePressEvent ( self , QGraphicsSceneMouseEvent   event )

重实现自 QGraphicsItem.mousePressEvent ().

QGraphicsTextItem.mouseReleaseEvent ( self , QGraphicsSceneMouseEvent   event )

重实现自 QGraphicsItem.mouseReleaseEvent ().

QPainterPath QGraphicsTextItem.opaqueArea ( self )

重实现自 QGraphicsItem.opaqueArea ().

bool QGraphicsTextItem.openExternalLinks ( self )

QGraphicsTextItem.paint ( self , QPainter   painter , QStyleOptionGraphicsItem   option , QWidget   widget )

重实现自 QGraphicsItem.paint ().

bool QGraphicsTextItem.sceneEvent ( self , QEvent   event )

重实现自 QGraphicsItem.sceneEvent ().

QGraphicsTextItem.setDefaultTextColor ( self , QColor   c )

Sets the color for unformatted text to col .

另请参阅 defaultTextColor ().

QGraphicsTextItem.setDocument ( self , QTextDocument   document )

Sets the text document document on the item.

另请参阅 document ().

QGraphicsTextItem.setFont ( self , QFont   font )

Sets the font used to render the text item to font .

另请参阅 font ().

QGraphicsTextItem.setHtml ( self , QString  html )

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 .

QGraphicsTextItem.setOpenExternalLinks ( self , bool  open )

QGraphicsTextItem.setPlainText ( self , QString  text )

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 ().

QGraphicsTextItem.setTabChangesFocus ( self , bool  b )

b is true, the Tab key will cause the widget to change focus; otherwise, the tab key will insert a tab into the 文档。

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.

该函数在 Qt 4.5 引入。

另请参阅 tabChangesFocus (), ItemIsFocusable ,和 textInteractionFlags ().

QGraphicsTextItem.setTextCursor ( self , QTextCursor   cursor )

QGraphicsTextItem.setTextInteractionFlags ( self , Qt.TextInteractionFlags   flags )

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 ().

QGraphicsTextItem.setTextWidth ( self , float  width )

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 ().

QPainterPath QGraphicsTextItem.shape ( self )

重实现自 QGraphicsItem.shape ().

bool QGraphicsTextItem.tabChangesFocus ( self )

返回 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 ().

QTextCursor QGraphicsTextItem.textCursor ( self )

Qt.TextInteractionFlags QGraphicsTextItem.textInteractionFlags ( self )

Returns the current text interaction flags.

另请参阅 setTextInteractionFlags ().

float QGraphicsTextItem.textWidth ( self )

Returns the text width.

The width is calculated with the QTextDocument that QGraphicsTextItem keeps internally.

另请参阅 setTextWidth () 和 QTextDocument.textWidth ().

QString QGraphicsTextItem.toHtml ( self )

Returns the item's text converted to HTML, or an empty QString if no text has been set.

另请参阅 setHtml ().

QString QGraphicsTextItem.toPlainText ( self )

Returns the item's text converted to plain text, or an empty QString if no text has been set.

另请参阅 setPlainText ().

int QGraphicsTextItem.type ( self )

重实现自 QGraphicsItem.type ().


Qt Signal Documentation

void linkActivated (const QString&)

This is the default overload of this signal.

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 ().

void linkHovered (const QString&)

This is the default overload of this signal.

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 ().