本文整理汇总了Python中PyQt5.QtWidgets.QGraphicsItem.itemChange方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsItem.itemChange方法的具体用法?Python QGraphicsItem.itemChange怎么用?Python QGraphicsItem.itemChange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QGraphicsItem
的用法示例。
在下文中一共展示了QGraphicsItem.itemChange方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: itemChange
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsItem import itemChange [as 别名]
def itemChange(self, change, value):
return QGraphicsItem.itemChange(self, change, value)
# for selection changes test against QGraphicsItem.ItemSelectedChange
# intercept the change instead of the has changed to enable features.
if change == QGraphicsItem.ItemSelectedChange and self.scene():
active_tool = self._getActiveTool()
if active_tool.methodPrefix() == "selectTool":
viewroot = self._viewroot
current_filter_dict = viewroot.selectionFilterDict()
selection_group = viewroot.strandItemSelectionGroup()
# only add if the selection_group is not locked out
is_normal_select = selection_group.isNormalSelect()
if value == True and (self._filter_name in current_filter_dict or not is_normal_select):
if self._strand_filter in current_filter_dict:
if self.group() != selection_group:
self.setSelectedColor(True)
# This should always be the case, but...
if is_normal_select:
selection_group.pendToAdd(self)
selection_group.setSelectionLock(selection_group)
selection_group.pendToAdd(self._low_cap)
selection_group.pendToAdd(self._high_cap)
# this else will capture the error. Basically, the
# strandItem should be member of the group before this
# ever gets fired
else:
selection_group.addToGroup(self)
return True
else:
return False
# end if
elif value == True:
# Don't select
return False
# end elif
else:
# Deselect
# print "Deselecting strand"
selection_group.pendToRemove(self)
self.setSelectedColor(False)
selection_group.pendToRemove(self._low_cap)
selection_group.pendToRemove(self._high_cap)
return False
# end else
# end if
elif active_tool.methodPrefix() == "paintTool":
viewroot = self._viewroot
current_filter_dict = viewroot.selectionFilterDict()
if self._strand_filter in current_filter_dict:
if not active_tool.isMacrod():
active_tool.setMacrod()
self.paintToolMousePress(None, None)
# end elif
return False
# end if
return QGraphicsItem.itemChange(self, change, value)
示例2: itemChange
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsItem import itemChange [as 别名]
def itemChange(self, change, value):
"""
Public method called when an items state changes.
@param change the item's change (QGraphicsItem.GraphicsItemChange)
@param value the value of the change
@return adjusted values
"""
if change == QGraphicsItem.ItemPositionChange:
# 1. remember to adjust associations
self.shouldAdjustAssociations = True
# 2. ensure the new position is inside the scene
rect = self.scene().sceneRect()
if not rect.contains(value):
# keep the item inside the scene
value.setX(min(rect.right(), max(value.x(), rect.left())))
value.setY(min(rect.bottom(), max(value.y(), rect.top())))
return value
return QGraphicsItem.itemChange(self, change, value)
示例3: itemChange
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsItem import itemChange [as 别名]
def itemChange(self, change: QGraphicsItem.GraphicsItemChange,
value: Any) -> bool:
"""Used for selection of the :class:`StrandItem`
Args:
change: parameter that is changing
value : new value whose type depends on the ``change`` argument
Returns:
If the change is a ``QGraphicsItem.ItemSelectedChange``::
``True`` if selected, other ``False``
Otherwise default to :meth:`QGraphicsItem.itemChange()` result
"""
# for selection changes test against QGraphicsItem.ItemSelectedChange
# intercept the change instead of the has changed to enable features.
if change == QGraphicsItem.ItemSelectedChange and self.scene():
active_tool = self._getActiveTool()
if active_tool.methodPrefix() == "selectTool":
viewroot = self._viewroot
current_filter_set = viewroot.selectionFilterSet()
selection_group = viewroot.strandItemSelectionGroup()
# only add if the selection_group is not locked out
is_normal_select = selection_group.isNormalSelect()
if value == True and (self.FILTER_NAME in current_filter_set or not is_normal_select):
if all(f in current_filter_set for f in self.strandFilter()):
if self.group() != selection_group:
self.setSelectedColor(True)
# This should always be the case, but...
if is_normal_select:
selection_group.pendToAdd(self)
selection_group.setSelectionLock(selection_group)
selection_group.pendToAdd(self._low_cap)
selection_group.pendToAdd(self._high_cap)
# this else will capture the error. Basically, the
# strandItem should be member of the group before this
# ever gets fired
else:
selection_group.addToGroup(self)
return True
else:
return False
# end if
elif value == True: # noqa value resolves to int from QVariant, must use ==
# Don't select
return False
# end elif
else:
# Deselect
# print("Deselecting strand")
selection_group.pendToRemove(self)
self.setSelectedColor(False)
selection_group.pendToRemove(self._low_cap)
selection_group.pendToRemove(self._high_cap)
return False
# end else
# end if
elif active_tool.methodPrefix() == "paintTool":
viewroot = self._viewroot
current_filter_set = viewroot.selectionFilterSet()
if all(f in current_filter_set for f in self.strandFilter()):
if not active_tool.isMacrod():
active_tool.setMacrod()
self.paintToolMousePress(None, None)
# end elif
return False
# end if
return QGraphicsItem.itemChange(self, change, value)