本文整理匯總了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: