[QtGui module]

该QGraphicsTextItem类提供了一个文本项,您可以添加到QGraphicsScene显示格式化文本。More…

继承QGraphicsObject

Methods

  • __init__ (self, QGraphicsItem parent = None, QGraphicsScene scene = None)
  • __init__ (self, QString text, QGraphicsItem parent = None, QGraphicsScene scene = None)
  • adjustSize (self)
  • QRectF boundingRect (self)
  • bool contains (self, QPointF point)
  • contextMenuEvent (self, QGraphicsSceneContextMenuEvent event)
  • QColor defaultTextColor (self)
  • QTextDocument document (self)
  • dragEnterEvent (self, QGraphicsSceneDragDropEvent event)
  • dragLeaveEvent (self, QGraphicsSceneDragDropEvent event)
  • dragMoveEvent (self, QGraphicsSceneDragDropEvent event)
  • dropEvent (self, QGraphicsSceneDragDropEvent event)
  • focusInEvent (self, QFocusEvent event)
  • focusOutEvent (self, QFocusEvent event)
  • QFont font (self)
  • hoverEnterEvent (self, QGraphicsSceneHoverEvent event)
  • hoverLeaveEvent (self, QGraphicsSceneHoverEvent event)
  • hoverMoveEvent (self, QGraphicsSceneHoverEvent event)
  • inputMethodEvent (self, QInputMethodEvent event)
  • QVariant inputMethodQuery (self, Qt.InputMethodQuery query)
  • bool isObscuredBy (self, QGraphicsItem item)
  • keyPressEvent (self, QKeyEvent event)
  • keyReleaseEvent (self, QKeyEvent event)
  • mouseDoubleClickEvent (self, QGraphicsSceneMouseEvent event)
  • mouseMoveEvent (self, QGraphicsSceneMouseEvent event)
  • mousePressEvent (self, QGraphicsSceneMouseEvent event)
  • mouseReleaseEvent (self, QGraphicsSceneMouseEvent event)
  • QPainterPath opaqueArea (self)
  • bool openExternalLinks (self)
  • paint (self, QPainter painter, QStyleOptionGraphicsItem option, QWidget widget)
  • bool sceneEvent (self, QEvent event)
  • setDefaultTextColor (self, QColor c)
  • setDocument (self, QTextDocument document)
  • setFont (self, QFont font)
  • setHtml (self, QString html)
  • setOpenExternalLinks (self, bool open)
  • setPlainText (self, QString text)
  • setTabChangesFocus (self, bool b)
  • setTextCursor (self, QTextCursor cursor)
  • setTextInteractionFlags (self, Qt.TextInteractionFlags flags)
  • setTextWidth (self, float width)
  • QPainterPath shape (self)
  • bool tabChangesFocus (self)
  • QTextCursor textCursor (self)
  • Qt.TextInteractionFlags textInteractionFlags (self)
  • float textWidth (self)
  • QString toHtml (self)
  • QString toPlainText (self)
  • int type (self)

Qt Signals

  • void linkActivated (const QString&)
  • void linkHovered (const QString&)

Detailed Description

该QGraphicsTextItem类提供了一个文本项,您可以添加到QGraphicsScene显示格式化文本。

如果只需要显示在一个项目纯文本,可以考虑使用QGraphicsSimpleTextItem代替。

要设置项的文本,一个传递QString到QGraphicsTextItem的构造函数,或调用setHtml()/setPlainText( ) 。

QGraphicsTextItem使用文本的格式大小和相关的字体提供合理的实施boundingRect( )shape()和contains( ) 。你可以通过调用设置字体setFont( ) 。

它有可能使该项目可编辑通过设置Qt.TextEditorInteraction使用标志setTextInteractionFlags( ) 。

该项目的首选文本的宽度可以使用设置setTextWidth( ),并使用获得的textWidth( ) 。

Note:为了使在中心的HTML文本,该项目的文本宽度必须设置。

QGraphicsTextItem Class Reference - 图1

Note:QGraphicsTextItem接受hover events在默认情况下。您可以更改此setAcceptHoverEvents()


Method Documentation

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

parent的说法,如果不是没有,原因self通过Qt的,而不是PyQt的拥有。

scene的说法,如果不是没有,原因self通过Qt的,而不是PyQt的拥有。

构造一个QGraphicsTextItemparent被传递给QGraphicsItem的构造。

See also QGraphicsScene.addItem( ) 。

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

parent的说法,如果不是没有,原因self通过Qt的,而不是PyQt的拥有。

scene的说法,如果不是没有,原因self通过Qt的,而不是PyQt的拥有。

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

See also QGraphicsScene.addItem( ) 。

  1. QGraphicsTextItem.adjustSize (self)

调整文本项到一个合理的规模。

  1. QRectF QGraphicsTextItem.boundingRect (self)

从重新实现QGraphicsItem.boundingRect( ) 。

  1. bool QGraphicsTextItem.contains (self, QPointF point)

从重新实现QGraphicsItem.contains( ) 。

  1. QGraphicsTextItem.contextMenuEvent (self, QGraphicsSceneContextMenuEvent event)

从重新实现QGraphicsItem.contextMenuEvent( ) 。

  1. QColor QGraphicsTextItem.defaultTextColor (self)

[

返回用于为无格式文本的默认文本颜色。

](docs_qcolor.html)

See also setDefaultTextColor( ) 。

  1. QTextDocument QGraphicsTextItem.document (self)

[

返回该项目的文本文档。

](docs_qtextdocument.html)

See also setDocument( ) 。

  1. QGraphicsTextItem.dragEnterEvent (self, QGraphicsSceneDragDropEvent event)

从重新实现QGraphicsItem.dragEnterEvent( ) 。

  1. QGraphicsTextItem.dragLeaveEvent (self, QGraphicsSceneDragDropEvent event)

从重新实现QGraphicsItem.dragLeaveEvent( ) 。

  1. QGraphicsTextItem.dragMoveEvent (self, QGraphicsSceneDragDropEvent event)

从重新实现QGraphicsItem.dragMoveEvent( ) 。

  1. QGraphicsTextItem.dropEvent (self, QGraphicsSceneDragDropEvent event)

从重新实现QGraphicsItem.dropEvent( ) 。

  1. QGraphicsTextItem.focusInEvent (self, QFocusEvent event)

从重新实现QGraphicsItem.focusInEvent( ) 。

  1. QGraphicsTextItem.focusOutEvent (self, QFocusEvent event)

从重新实现QGraphicsItem.focusOutEvent( ) 。

  1. QFont QGraphicsTextItem.font (self)

[

返回项的字体,这是用来呈现的文本。

](docs_qfont.html)

See also setFont( ) 。

  1. QGraphicsTextItem.hoverEnterEvent (self, QGraphicsSceneHoverEvent event)

从重新实现QGraphicsItem.hoverEnterEvent( ) 。

  1. QGraphicsTextItem.hoverLeaveEvent (self, QGraphicsSceneHoverEvent event)

从重新实现QGraphicsItem.hoverLeaveEvent( ) 。

  1. QGraphicsTextItem.hoverMoveEvent (self, QGraphicsSceneHoverEvent event)

从重新实现QGraphicsItem.hoverMoveEvent( ) 。

  1. QGraphicsTextItem.inputMethodEvent (self, QInputMethodEvent event)

从重新实现QGraphicsItem.inputMethodEvent( ) 。

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

从重新实现QGraphicsItem.inputMethodQuery( ) 。

  1. bool QGraphicsTextItem.isObscuredBy (self, QGraphicsItem item)

从重新实现QGraphicsItem.isObscuredBy( ) 。

  1. QGraphicsTextItem.keyPressEvent (self, QKeyEvent event)

从重新实现QGraphicsItem.keyPressEvent( ) 。

  1. QGraphicsTextItem.keyReleaseEvent (self, QKeyEvent event)

从重新实现QGraphicsItem.keyReleaseEvent( ) 。

  1. QGraphicsTextItem.mouseDoubleClickEvent (self, QGraphicsSceneMouseEvent event)

从重新实现QGraphicsItem.mouseDoubleClickEvent( ) 。

  1. QGraphicsTextItem.mouseMoveEvent (self, QGraphicsSceneMouseEvent event)

从重新实现QGraphicsItem.mouseMoveEvent( ) 。

  1. QGraphicsTextItem.mousePressEvent (self, QGraphicsSceneMouseEvent event)

从重新实现QGraphicsItem.mousePressEvent( ) 。

  1. QGraphicsTextItem.mouseReleaseEvent (self, QGraphicsSceneMouseEvent event)

从重新实现QGraphicsItem.mouseReleaseEvent( ) 。

  1. QPainterPath QGraphicsTextItem.opaqueArea (self)

从重新实现QGraphicsItem.opaqueArea( ) 。

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

从重新实现QGraphicsItem.paint( ) 。

  1. bool QGraphicsTextItem.sceneEvent (self, QEvent event)

从重新实现QGraphicsItem.sceneEvent( ) 。

  1. QGraphicsTextItem.setDefaultTextColor (self, QColor c)

设置为无格式文本的颜色col

See also defaultTextColor( ) 。

  1. QGraphicsTextItem.setDocument (self, QTextDocument document)

设置文本文件document该项目。

See also document( ) 。

  1. QGraphicsTextItem.setFont (self, QFont font)

设置用于文本渲染项目的字体font

See also font( ) 。

  1. QGraphicsTextItem.setHtml (self, QString html)

设置项的文本text,假设该文本是HTML格式的。如果该项目具有键盘输入焦点,此功能也将调用ensureVisible()来确保文本是在所有视口中可见。

See also toHtml( )hasFocus()和QGraphicsSimpleTextItem

  1. QGraphicsTextItem.setOpenExternalLinks (self, bool open)
  1. QGraphicsTextItem.setPlainText (self, QString text)

设置项的文本text。如果该项目具有键盘输入焦点,此功能也将调用ensureVisible()来确保文本是在所有视口中可见。

See also toHtml()和hasFocus( ) 。

  1. QGraphicsTextItem.setTabChangesFocus (self, bool b)

If b是真的,Tab键将导致小部件来改变焦点,否则, tab键将插入一个标籤到文档中。

在某些情况下文本编辑不应该允许用户输入制表或改变使用的缩进Tab关键,因为这打破了焦点链。默认值为False 。

此功能被引入Qt的4.5 。

See also tabChangesFocus( )ItemIsFocusabletextInteractionFlags( ) 。

  1. QGraphicsTextItem.setTextCursor (self, QTextCursor cursor)
  1. QGraphicsTextItem.setTextInteractionFlags (self, Qt.TextInteractionFlags flags)

设置标志flags指定如何将文本项目应响应用户的输入。

默认为QGraphicsTextItem is Qt.NoTextInteraction。此功能也影响到ItemIsFocusable QGraphicsItem标志通过设置它,如果flags是从不同的Qt.NoTextInteraction并且清除它,否则。

默认情况下,文本是只读的。改造项目到编辑器中,设置Qt.TextEditable标志。

See also textInteractionFlags( ) 。

  1. QGraphicsTextItem.setTextWidth (self, float width)

设置项目的文本的首选宽度。如果实际文本比指定的宽度更宽那么它将被分成多行。

If width被设置为-1,则文本不会断成多行,除非它是通过显式换行符或一个新的段落执行。

默认值是-1 。

需要注意的是QGraphicsTextItem养了QTextDocument在内部,它是用来计算文本宽度。

See also textWidth()和QTextDocument.setTextWidth( ) 。

  1. QPainterPath QGraphicsTextItem.shape (self)

从重新实现QGraphicsItem.shape( ) 。

  1. bool QGraphicsTextItem.tabChangesFocus (self)

返回True如果Tab键将导致小部件来改变焦点,否则返回False 。

默认情况下,这种行为被禁止,这个函数将返回False 。

此功能被引入Qt的4.5 。

See also setTabChangesFocus( ) 。

  1. QTextCursor QGraphicsTextItem.textCursor (self)
  1. Qt.TextInteractionFlags QGraphicsTextItem.textInteractionFlags (self)

[

返回当前文本的互动标志。

](docs_index.htm)

See also setTextInteractionFlags( ) 。

  1. float QGraphicsTextItem.textWidth (self)

返回文本的宽度。

宽度的计算方法与QTextDocumentQGraphicsTextItem内部保存。

See also setTextWidth()和QTextDocument.textWidth( ) 。

  1. QString QGraphicsTextItem.toHtml (self)

返回项的文本转换为HTML ,或空QString如果没有文本已定。

See also setHtml( ) 。

  1. QString QGraphicsTextItem.toPlainText (self)

返回项的文本转换为纯文本或空QString如果没有文本已定。

See also setPlainText( ) 。

  1. int QGraphicsTextItem.type (self)

从重新实现QGraphicsItem.type( ) 。


Qt Signal Documentation

  1. void linkActivated (const QString&)

这是该信号的默认超载。

当用户点击一个文本项,它使一个链接这个信号被发射Qt.LinksAccessibleByMouse or Qt.LinksAccessibleByKeyboardlink是被点击的链接。

See also setTextInteractionFlags( ) 。

  1. void linkHovered (const QString&)

这是该信号的默认超载。

当用户将鼠标悬停在一个文本项,使一个链接这个信号被发射Qt.LinksAccessibleByMouselink是被悬停在链接。

See also setTextInteractionFlags( ) 。