本文整理匯總了Python中AnyQt.QtWidgets.QGraphicsTextItem.setPlainText方法的典型用法代碼示例。如果您正苦於以下問題:Python QGraphicsTextItem.setPlainText方法的具體用法?Python QGraphicsTextItem.setPlainText怎麽用?Python QGraphicsTextItem.setPlainText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類AnyQt.QtWidgets.QGraphicsTextItem
的用法示例。
在下文中一共展示了QGraphicsTextItem.setPlainText方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: VennIntersectionArea
# 需要導入模塊: from AnyQt.QtWidgets import QGraphicsTextItem [as 別名]
# 或者: from AnyQt.QtWidgets.QGraphicsTextItem import setPlainText [as 別名]
class VennIntersectionArea(QGraphicsPathItem):
def __init__(self, parent=None, text=""):
super(QGraphicsPathItem, self).__init__(parent)
self.setAcceptHoverEvents(True)
self.setPen(QPen(Qt.NoPen))
self.text = QGraphicsTextItem(self)
layout = self.text.document().documentLayout()
layout.documentSizeChanged.connect(self._onLayoutChanged)
self._text = ""
self._anchor = QPointF()
def setText(self, text):
if self._text != text:
self._text = text
self.text.setPlainText(text)
def text(self):
return self._text
def setTextAnchor(self, pos):
if self._anchor != pos:
self._anchor = pos
self._updateTextAnchor()
def hoverEnterEvent(self, event):
self.setZValue(self.zValue() + 1)
return QGraphicsPathItem.hoverEnterEvent(self, event)
def hoverLeaveEvent(self, event):
self.setZValue(self.zValue() - 1)
return QGraphicsPathItem.hoverLeaveEvent(self, event)
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
if event.modifiers() & Qt.AltModifier:
self.setSelected(False)
elif event.modifiers() & Qt.ControlModifier:
self.setSelected(not self.isSelected())
elif event.modifiers() & Qt.ShiftModifier:
self.setSelected(True)
else:
for area in self.parentWidget().vennareas():
area.setSelected(False)
self.setSelected(True)
def mouseReleaseEvent(self, event):
pass
def paint(self, painter, option, widget=None):
painter.save()
path = self.path()
brush = QBrush(self.brush())
pen = QPen(self.pen())
if option.state & QStyle.State_Selected:
pen.setColor(Qt.red)
brush.setStyle(Qt.DiagCrossPattern)
brush.setColor(QColor(40, 40, 40, 100))
elif option.state & QStyle.State_MouseOver:
pen.setColor(Qt.blue)
if option.state & QStyle.State_MouseOver:
brush.setColor(QColor(100, 100, 100, 100))
if brush.style() == Qt.NoBrush:
# Make sure the highlight is actually visible.
brush.setStyle(Qt.SolidPattern)
painter.setPen(pen)
painter.setBrush(brush)
painter.drawPath(path)
painter.restore()
def itemChange(self, change, value):
if change == QGraphicsPathItem.ItemSelectedHasChanged:
self.setZValue(self.zValue() + (1 if value else -1))
return QGraphicsPathItem.itemChange(self, change, value)
def _updateTextAnchor(self):
rect = self.text.boundingRect()
pos = anchor_rect(rect, self._anchor)
self.text.setPos(pos)
def _onLayoutChanged(self):
self._updateTextAnchor()
示例2: LinkItem
# 需要導入模塊: from AnyQt.QtWidgets import QGraphicsTextItem [as 別名]
# 或者: from AnyQt.QtWidgets.QGraphicsTextItem import setPlainText [as 別名]
#.........這裏部分代碼省略.........
# TODO: make the curve tangent orthogonal to the anchors path.
path = QPainterPath()
path.moveTo(source_pos)
path.cubicTo(source_pos + QPointF(cp_offset, 0),
sink_pos - QPointF(cp_offset, 0),
sink_pos)
self.curveItem.setCurvePath(path)
self.sourceIndicator.setPos(source_pos)
self.sinkIndicator.setPos(sink_pos)
self.__updateText()
else:
self.setHoverState(False)
self.curveItem.setPath(QPainterPath())
def __updateText(self):
self.prepareGeometryChange()
self.__boundingRect = None
if self.__sourceName or self.__sinkName:
if self.__sourceName != self.__sinkName:
text = "{0} \u2192 {1}".format(self.__sourceName,
self.__sinkName)
else:
# If the names are the same show only one.
# Is this right? If the sink has two input channels of the
# same type having the name on the link help elucidate
# the scheme.
text = self.__sourceName
else:
text = ""
self.linkTextItem.setPlainText(text)
path = self.curveItem.curvePath()
if not path.isEmpty():
center = path.pointAtPercent(0.5)
angle = path.angleAtPercent(0.5)
brect = self.linkTextItem.boundingRect()
transform = QTransform()
transform.translate(center.x(), center.y())
transform.rotate(-angle)
# Center and move above the curve path.
transform.translate(-brect.width() / 2, -brect.height())
self.linkTextItem.setTransform(transform)
def removeLink(self):
self.setSinkItem(None)
self.setSourceItem(None)
self.__updateCurve()
def setHoverState(self, state):
if self.hover != state:
self.prepareGeometryChange()
self.__boundingRect = None
self.hover = state
self.sinkIndicator.setHoverState(state)
self.sourceIndicator.setHoverState(state)
self.curveItem.setHoverState(state)
self.__updatePen()