本文整理汇总了Python中AnyQt.QtWidgets.QGraphicsWidget.setParentItem方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsWidget.setParentItem方法的具体用法?Python QGraphicsWidget.setParentItem怎么用?Python QGraphicsWidget.setParentItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtWidgets.QGraphicsWidget
的用法示例。
在下文中一共展示了QGraphicsWidget.setParentItem方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __updateState
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsWidget [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsWidget import setParentItem [as 别名]
def __updateState(self):
"""
Update the widget with the new source/sink node signal descriptions.
"""
widget = QGraphicsWidget()
widget.setLayout(QGraphicsGridLayout())
# Space between left and right anchors
widget.layout().setHorizontalSpacing(50)
left_node = EditLinksNode(self, direction=Qt.LeftToRight,
node=self.source)
left_node.setSizePolicy(QSizePolicy.MinimumExpanding,
QSizePolicy.MinimumExpanding)
right_node = EditLinksNode(self, direction=Qt.RightToLeft,
node=self.sink)
right_node.setSizePolicy(QSizePolicy.MinimumExpanding,
QSizePolicy.MinimumExpanding)
left_node.setMinimumWidth(150)
right_node.setMinimumWidth(150)
widget.layout().addItem(left_node, 0, 0,)
widget.layout().addItem(right_node, 0, 1,)
title_template = "<center><b>{0}<b></center>"
left_title = GraphicsTextWidget(self)
left_title.setHtml(title_template.format(escape(self.source.title)))
left_title.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
right_title = GraphicsTextWidget(self)
right_title.setHtml(title_template.format(escape(self.sink.title)))
right_title.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
widget.layout().addItem(left_title, 1, 0,
alignment=Qt.AlignHCenter | Qt.AlignTop)
widget.layout().addItem(right_title, 1, 1,
alignment=Qt.AlignHCenter | Qt.AlignTop)
widget.setParentItem(self)
max_w = max(left_node.sizeHint(Qt.PreferredSize).width(),
right_node.sizeHint(Qt.PreferredSize).width())
# fix same size
left_node.setMinimumWidth(max_w)
right_node.setMinimumWidth(max_w)
left_title.setMinimumWidth(max_w)
right_title.setMinimumWidth(max_w)
self.layout().addItem(widget)
self.layout().activate()
self.sourceNodeWidget = left_node
self.sinkNodeWidget = right_node
self.sourceNodeTitle = left_title
self.sinkNodeTitle = right_title
示例2: __updateState
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsWidget [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsWidget import setParentItem [as 别名]
def __updateState(self):
"""
Update the widget with the new source/sink node signal descriptions.
"""
widget = QGraphicsWidget()
widget.setLayout(QGraphicsGridLayout())
# Space between left and right anchors
widget.layout().setHorizontalSpacing(50)
left_node = EditLinksNode(self, direction=Qt.LeftToRight,
node=self.source)
left_node.setSizePolicy(QSizePolicy.MinimumExpanding,
QSizePolicy.MinimumExpanding)
right_node = EditLinksNode(self, direction=Qt.RightToLeft,
node=self.sink)
right_node.setSizePolicy(QSizePolicy.MinimumExpanding,
QSizePolicy.MinimumExpanding)
left_node.setMinimumWidth(150)
right_node.setMinimumWidth(150)
widget.layout().addItem(left_node, 0, 0,)
widget.layout().addItem(right_node, 0, 1,)
title_template = "<center><b>{0}<b></center>"
left_title = GraphicsTextWidget(self)
left_title.setHtml(title_template.format(escape(self.source.title)))
left_title.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
right_title = GraphicsTextWidget(self)
right_title.setHtml(title_template.format(escape(self.sink.title)))
right_title.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
widget.layout().addItem(left_title, 1, 0,
alignment=Qt.AlignHCenter | Qt.AlignTop)
widget.layout().addItem(right_title, 1, 1,
alignment=Qt.AlignHCenter | Qt.AlignTop)
widget.setParentItem(self)
max_w = max(left_node.sizeHint(Qt.PreferredSize).width(),
right_node.sizeHint(Qt.PreferredSize).width())
# fix same size
left_node.setMinimumWidth(max_w)
right_node.setMinimumWidth(max_w)
left_title.setMinimumWidth(max_w)
right_title.setMinimumWidth(max_w)
self.layout().addItem(widget)
self.layout().activate()
self.sourceNodeWidget = left_node
self.sinkNodeWidget = right_node
self.sourceNodeTitle = left_title
self.sinkNodeTitle = right_title
self.__resetAnchorStates()
# AnchorHover hover over anchor before hovering over line
class AnchorHover(QGraphicsRectItem):
def __init__(self, anchor, parent=None):
QGraphicsRectItem.__init__(self, parent=parent)
self.setAcceptHoverEvents(True)
self.anchor = anchor
self.setRect(anchor.boundingRect())
self.setPos(self.mapFromScene(anchor.scenePos()))
self.setFlag(QGraphicsItem.ItemHasNoContents, True)
def hoverEnterEvent(self, event):
if self.anchor.isEnabled():
self.anchor.hoverEnterEvent(event)
else:
event.ignore()
def hoverLeaveEvent(self, event):
if self.anchor.isEnabled():
self.anchor.hoverLeaveEvent(event)
else:
event.ignore()
for anchor in left_node.channelAnchors + right_node.channelAnchors:
anchor_hover = AnchorHover(anchor, parent=self)
anchor_hover.setZValue(2.0)