本文整理汇总了Python中PyQt5.QtWidgets.QGraphicsItem.mousePressEvent方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsItem.mousePressEvent方法的具体用法?Python QGraphicsItem.mousePressEvent怎么用?Python QGraphicsItem.mousePressEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QGraphicsItem
的用法示例。
在下文中一共展示了QGraphicsItem.mousePressEvent方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mousePressEvent
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsItem import mousePressEvent [as 别名]
def mousePressEvent(self, event):
"""
All mousePressEvents are passed to the group if it's in a group
"""
selection_group = self.group()
if selection_group != None:
selection_group.mousePressEvent(event)
else:
QGraphicsItem.mousePressEvent(self, event)
示例2: mousePressEvent
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsItem import mousePressEvent [as 别名]
def mousePressEvent(self, event):
'''Handle mouse press event.
Argument(s):
event (QGraphicsSceneMouseEvent): Graphics scene mouse event
'''
QGraphicsItem.mousePressEvent(self, event)
# Get the focus
if event.buttons() == Qt.LeftButton:
self.getFocus(self.id)
示例3: mousePressEvent
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsItem import mousePressEvent [as 别名]
def mousePressEvent(self, event):
"""
Parses a mousePressEvent, calling the approproate tool method as
necessary. Stores _move_idx for future comparison.
"""
if event.button() != Qt.LeftButton:
event.ignore()
QGraphicsItem.mousePressEvent(self, event)
return
self.scene().views()[0].addToPressList(self)
self._move_idx = int(floor((self.x() + event.pos().x()) / _BASE_WIDTH))
tool_method_name = self._getActiveTool().methodPrefix() + "MousePress"
if hasattr(self, tool_method_name): # if the tool method exists
modifiers = event.modifiers()
getattr(self, tool_method_name)(modifiers) # call tool method
示例4: mousePressEvent
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsItem import mousePressEvent [as 别名]
def mousePressEvent(self, event):
"""Handle mouse press event.
Argument(s):
event (QGraphicsSceneMouseEvent): Graphics scene mouse event
"""
QGraphicsItem.mousePressEvent(self, event)
# Create the semi-edge and get the focus
if event.buttons() == Qt.LeftButton:
self.getFocus(self.id)
self.semiEdge = GraphicsSemiEdge(event.scenePos(), self)
self.scene().addItem(self.semiEdge)
elif event.buttons() == Qt.RightButton:
self.contextMenu.popup(event.screenPos())
示例5: mousePressEvent
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsItem import mousePressEvent [as 别名]
def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
"""All mousePressEvents are passed to the group if it's in a group
Args:
event: Description
"""
selection_group = self.group()
if selection_group is not None:
selection_group.mousePressEvent(event)
elif event.button() == Qt.RightButton:
current_filter_set = self._viewroot.selectionFilterSet()
if self.FILTER_NAME in current_filter_set and self.part().isZEditable():
self._right_mouse_move = True
self.drag_last_position = event.scenePos()
self.handle_start = self.pos()
else:
QGraphicsItem.mousePressEvent(self, event)
示例6: mousePressEvent
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsItem import mousePressEvent [as 别名]
def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
"""Handler for user mouse press.
Args:
event: Contains item, scene, and screen coordinates of the event,
and previous event.
"""
self._viewroot.clearSelectionsIfActiveTool()
self.unsetActiveVirtualHelixItem()
return QGraphicsItem.mousePressEvent(self, event)
示例7: mousePressEvent
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsItem import mousePressEvent [as 别名]
def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
"""Parses a mousePressEvent. Stores _move_idx and _offset_idx for
future comparison.
"""
self._high_drag_bound = self._model_part.getProperty('max_vhelix_length') - self.width()
if event.modifiers() & Qt.ShiftModifier or self._moving_via_handle:
self.setCursor(Qt.ClosedHandCursor)
self._start_idx_low = self._idx_low
self._start_idx_high = self._idx_high
self._delta = 0
self._move_idx = int(floor((self.x()+event.pos().x()) / BASE_WIDTH))
self._offset_idx = int(floor(event.pos().x()) / BASE_WIDTH)
else:
return QGraphicsItem.mousePressEvent(self, event)
示例8: createToolMousePress
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsItem import mousePressEvent [as 别名]
def createToolMousePress(self, tool: AbstractGridToolT,
event: QGraphicsSceneMouseEvent,
alt_event=None):
"""Summary
Args:
tool: Description
event: Description
alt_event (None, optional): Description
"""
# 1. get point in model coordinates:
part = self._model_part
if alt_event is None:
pt = tool.eventToPosition(self, event)
else:
pt = alt_event.pos()
if pt is None:
tool.deactivate()
return QGraphicsItem.mousePressEvent(self, event)
part_pt_tuple: Vec3T = self.getModelPos(pt)
mod = Qt.MetaModifier
if not (event.modifiers() & mod):
pass
# don't create a new VirtualHelix if the click overlaps with existing
# VirtualHelix
current_id_num = tool.idNum()
check = part.isVirtualHelixNearPoint(part_pt_tuple, current_id_num)
# print("current_id_num", current_id_num, check)
# print(part_pt_tuple)
tool.setPartItem(self)
if check:
id_num = part.getVirtualHelixAtPoint(part_pt_tuple)
# print("got a check", id_num)
if id_num >= 0:
# print("restart", id_num)
vhi = self._virtual_helix_item_hash[id_num]
tool.setVirtualHelixItem(vhi)
tool.startCreation()
else:
# print("creating", part_pt_tuple)
part.createVirtualHelix(*part_pt_tuple)
id_num = part.getVirtualHelixAtPoint(part_pt_tuple)
vhi = self._virtual_helix_item_hash[id_num]
tool.setVirtualHelixItem(vhi)
tool.startCreation()
示例9: mousePressEvent
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsItem import mousePressEvent [as 别名]
def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
"""Event handler for when the mouse button is pressed inside
this item. If a tool-specific mouse press method is defined, it will be
called for the currently active tool. Otherwise, the default
:meth:`QGraphicsItem.mousePressEvent` will be called.
Note:
Only applies the event if the clicked item is in the part
item's active filter set.
Args:
event: contains parameters that describe the mouse event.
"""
if self.FILTER_NAME not in self._part_item.getFilterSet():
return
if event.button() == Qt.RightButton:
return
part_item = self._part_item
tool = part_item._getActiveTool()
tool_method_name = tool.methodPrefix() + "MousePress"
if hasattr(self, tool_method_name):
getattr(self, tool_method_name)(tool, part_item, event)
else:
QGraphicsItem.mousePressEvent(self, event)
示例10: mousePressEvent
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsItem import mousePressEvent [as 别名]
def mousePressEvent(self, event):
if event.button() == Qt.RightButton:
return
parent = self.parentItem()
if self.is_resizable and event.modifiers() & Qt.ShiftModifier:
self.model_bounds = parent.getModelMinBounds()
self.event_start_position = event.scenePos()
self.item_start = self.pos()
return
else:
parent = self.parentItem()
self.is_grabbing = True
self.event_start_position = event.pos()
parent.setMovable(True)
# ensure we handle window toggling during moves
qApp.focusWindowChanged.connect(self.focusWindowChangedSlot)
res = QGraphicsItem.mousePressEvent(parent, event)
return res
示例11: mousePressEvent
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsItem import mousePressEvent [as 别名]
def mousePressEvent(self, event):
if event.button() == Qt.RightButton:
return
parent = self.parentItem()
if self._group.is_resizable and event.modifiers() & Qt.ShiftModifier:
self.setCursor(self._resize_cursor)
self.model_bounds = parent.getModelMinBounds(handle_type=self._handle_type)
self.event_start_position = event.scenePos()
self.item_start = self.pos()
parent.showModelMinBoundsHint(self._handle_type, show=True)
event.setAccepted(True) # don't propagate
return
else:
self.setCursor(Qt.ClosedHandCursor)
parent = self.parentItem()
self._group.is_dragging = True
self.event_start_position = event.pos()
parent.setMovable(True)
# ensure we handle window toggling during moves
qApp.focusWindowChanged.connect(self.focusWindowChangedSlot)
res = QGraphicsItem.mousePressEvent(parent, event)
event.setAccepted(True) # don't propagate
return res
示例12: selectToolMousePress
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsItem import mousePressEvent [as 别名]
def selectToolMousePress(self, tool: AbstractGridToolT,
event: QGraphicsSceneMouseEvent):
"""
Args:
tool: Description
event: Description
"""
tool.setPartItem(self)
pt = tool.eventToPosition(self, event)
part_pt_tuple: Vec3T = self.getModelPos(pt)
part = self._model_part
if part.isVirtualHelixNearPoint(part_pt_tuple):
id_num = part.getVirtualHelixAtPoint(part_pt_tuple)
if id_num >= 0:
print(id_num)
loc = part.getCoordinate(id_num, 0)
print("VirtualHelix #{} at ({:.3f}, {:.3f})".format(id_num, loc[0], loc[1]))
else:
# tool.deselectItems()
tool.modelClearSelected()
else:
# tool.deselectItems()
tool.modelClearSelected()
return QGraphicsItem.mousePressEvent(self, event)
示例13: mousePressEvent
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsItem import mousePressEvent [as 别名]
def mousePressEvent(self, event):
# self.createOrAddBasesToVirtualHelix()
QGraphicsItem.mousePressEvent(self, event)