本文整理汇总了Python中AnyQt.QtWidgets.QGraphicsTextItem.setTransform方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsTextItem.setTransform方法的具体用法?Python QGraphicsTextItem.setTransform怎么用?Python QGraphicsTextItem.setTransform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtWidgets.QGraphicsTextItem
的用法示例。
在下文中一共展示了QGraphicsTextItem.setTransform方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LinkItem
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsTextItem import setTransform [as 别名]
#.........这里部分代码省略.........
# between the two ends
if not path.isEmpty():
# Use the distance between the start/end points as a measure of
# available space
diff = path.pointAtPercent(0.0) - path.pointAtPercent(1.0)
available_width = math.sqrt(diff.x() ** 2 + diff.y() ** 2)
# Get the ideal text width if it was unconstrained
doc = self.linkTextItem.document().clone(self)
doc.setTextWidth(-1)
idealwidth = doc.idealWidth()
doc.deleteLater()
# Constrain the text width but not below a certain min width
minwidth = 100
textwidth = max(minwidth, min(available_width, idealwidth))
self.linkTextItem.setTextWidth(textwidth)
else:
# Reset the fixed width
self.linkTextItem.setTextWidth(-1)
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()
def hoverEnterEvent(self, event):
# Hover enter event happens when the mouse enters any child object
# but we only want to show the 'hovered' shadow when the mouse
# is over the 'curveItem', so we install self as an event filter
# on the LinkCurveItem and listen to its hover events.
self.curveItem.installSceneEventFilter(self)
return super().hoverEnterEvent(event)
def hoverLeaveEvent(self, event):
# Remove the event filter to prevent unnecessary work in
# scene event filter when not needed
self.curveItem.removeSceneEventFilter(self)
return super().hoverLeaveEvent(event)
def changeEvent(self, event):
if event.type() == QEvent.PaletteChange: