本文整理汇总了Python中PyQt5.QtWidgets.QGraphicsScene.mouseMoveEvent方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsScene.mouseMoveEvent方法的具体用法?Python QGraphicsScene.mouseMoveEvent怎么用?Python QGraphicsScene.mouseMoveEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QGraphicsScene
的用法示例。
在下文中一共展示了QGraphicsScene.mouseMoveEvent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mouseMoveEvent
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsScene [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsScene import mouseMoveEvent [as 别名]
def mouseMoveEvent(self, event):
QGraphicsScene.mouseMoveEvent(self, event)
self.mousePos = event.scenePos()
if not (any((key.pressed for key in self.piano_keys))):
m_pos = event.scenePos()
if self.insert_mode and self.place_ghost: #placing a note
m_width = self.ghost_rect.x() + self.ghost_rect_orig_width
if m_pos.x() > m_width:
m_new_x = self.snap(m_pos.x())
self.ghost_rect.setRight(m_new_x)
self.ghost_note.setRect(self.ghost_rect)
#self.adjust_note_vel(event)
else:
m_pos = self.enforce_bounds(m_pos)
if self.insert_mode: #ghostnote follows mouse around
(m_new_x, m_new_y) = self.snap(m_pos.x(), m_pos.y())
self.ghost_rect.moveTo(m_new_x, m_new_y)
try:
self.ghost_note.setRect(self.ghost_rect)
except RuntimeError:
self.ghost_note = None
self.makeGhostNote(m_new_x, m_new_y)
elif self.marquee_select:
marquee_orig_pos = event.buttonDownScenePos(Qt.LeftButton)
if marquee_orig_pos.x() < m_pos.x() and marquee_orig_pos.y() < m_pos.y():
self.marquee_rect.setBottomRight(m_pos)
elif marquee_orig_pos.x() < m_pos.x() and marquee_orig_pos.y() > m_pos.y():
self.marquee_rect.setTopRight(m_pos)
elif marquee_orig_pos.x() > m_pos.x() and marquee_orig_pos.y() < m_pos.y():
self.marquee_rect.setBottomLeft(m_pos)
elif marquee_orig_pos.x() > m_pos.x() and marquee_orig_pos.y() > m_pos.y():
self.marquee_rect.setTopLeft(m_pos)
self.marquee.setRect(self.marquee_rect)
self.selected_notes = []
for item in self.collidingItems(self.marquee):
if item in self.notes:
self.selected_notes.append(item)
for note in self.notes:
if note in self.selected_notes: note.setSelected(True)
else: note.setSelected(False)
elif self.velocity_mode:
if Qt.LeftButton == event.buttons():
for note in self.selected_notes:
note.updateVelocity(event)
elif not self.marquee_select: #move selected
if Qt.LeftButton == event.buttons():
x = y = False
if any(note.back.stretch for note in self.selected_notes):
x = True
elif any(note.front.stretch for note in self.selected_notes):
y = True
for note in self.selected_notes:
note.back.stretch = x
note.front.stretch = y
note.moveEvent(event)