本文整理汇总了Python中PyQt4.QtGui.QGraphicsPathItem.brush方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsPathItem.brush方法的具体用法?Python QGraphicsPathItem.brush怎么用?Python QGraphicsPathItem.brush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QGraphicsPathItem
的用法示例。
在下文中一共展示了QGraphicsPathItem.brush方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TextAnnotation
# 需要导入模块: from PyQt4.QtGui import QGraphicsPathItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsPathItem import brush [as 别名]
class TextAnnotation(Annotation):
"""Text annotation item for the canvas scheme.
"""
editingFinished = Signal()
"""Emitted when the editing is finished (i.e. the item loses focus)."""
textEdited = Signal()
"""Emitted when the edited text changes."""
def __init__(self, parent=None, **kwargs):
Annotation.__init__(self, parent, **kwargs)
self.setFlag(QGraphicsItem.ItemIsMovable)
self.setFlag(QGraphicsItem.ItemIsSelectable)
self.setFocusPolicy(Qt.ClickFocus)
self.__textMargins = (2, 2, 2, 2)
rect = self.geometry().translated(-self.pos())
self.__framePathItem = QGraphicsPathItem(self)
self.__framePathItem.setPen(QPen(Qt.NoPen))
self.__textItem = GraphicsTextEdit(self)
self.__textItem.setPlaceholderText(self.tr("Enter text here"))
self.__textItem.setPos(2, 2)
self.__textItem.setTextWidth(rect.width() - 4)
self.__textItem.setTabChangesFocus(True)
self.__textItem.setTextInteractionFlags(Qt.NoTextInteraction)
self.__textItem.setFont(self.font())
self.__textInteractionFlags = Qt.NoTextInteraction
layout = self.__textItem.document().documentLayout()
layout.documentSizeChanged.connect(self.__onDocumentSizeChanged)
self.__updateFrame()
def adjustSize(self):
"""Resize to a reasonable size.
"""
self.__textItem.setTextWidth(-1)
self.__textItem.adjustSize()
size = self.__textItem.boundingRect().size()
left, top, right, bottom = self.textMargins()
geom = QRectF(self.pos(), size + QSizeF(left + right, top + bottom))
self.setGeometry(geom)
def setFramePen(self, pen):
"""Set the frame pen. By default Qt.NoPen is used (i.e. the frame
is not shown).
"""
self.__framePathItem.setPen(pen)
def framePen(self):
"""Return the frame pen.
"""
return self.__framePathItem.pen()
def setFrameBrush(self, brush):
"""Set the frame brush.
"""
self.__framePathItem.setBrush(brush)
def frameBrush(self):
"""Return the frame brush.
"""
return self.__framePathItem.brush()
def setPlainText(self, text):
"""Set the annotation plain text.
"""
self.__textItem.setPlainText(text)
def toPlainText(self):
return self.__textItem.toPlainText()
def setHtml(self, text):
"""Set the annotation rich text.
"""
self.__textItem.setHtml(text)
def toHtml(self):
return self.__textItem.toHtml()
def setDefaultTextColor(self, color):
"""Set the default text color.
"""
self.__textItem.setDefaultTextColor(color)
def defaultTextColor(self):
return self.__textItem.defaultTextColor()
def setTextMargins(self, left, top, right, bottom):
"""Set the text margins.
"""
margins = (left, top, right, bottom)
if self.__textMargins != margins:
self.__textMargins = margins
self.__textItem.setPos(left, top)
#.........这里部分代码省略.........