本文整理汇总了Python中PyQt5.QtWidgets.QGraphicsScene.itemAt方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsScene.itemAt方法的具体用法?Python QGraphicsScene.itemAt怎么用?Python QGraphicsScene.itemAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QGraphicsScene
的用法示例。
在下文中一共展示了QGraphicsScene.itemAt方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mousePressEvent
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsScene [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsScene import itemAt [as 别名]
def mousePressEvent(self, mouse_event):
if mouse_event.button() != Qt.LeftButton:
return
if self.my_mode == self.InsertItem:
x = mouse_event.scenePos().x() # // 50 * 50
y = mouse_event.scenePos().y() # // 50 * 50
item = self.insert_item(self.my_item_type, x, y)
self.itemInserted.emit(item.flume_component)
elif self.my_mode == self.InsertLine:
self.line = QGraphicsLineItem(QLineF(mouse_event.scenePos(),
mouse_event.scenePos()))
self.line.setPen(QPen(self.my_line_color, 2))
self.addItem(self.line)
elif self.my_mode == self.InsertText:
text_item = DiagramTextItem()
text_item.setFont(self.my_font)
text_item.setTextInteractionFlags(Qt.TextEditorInteraction)
text_item.setZValue(1000.0)
text_item.lostFocus.connect(self.editor_lost_focus)
# text_item.selectedChange.connect(self.itemSelected)
self.addItem(text_item)
text_item.setDefaultTextColor(self.my_text_color)
text_item.setPos(mouse_event.scenePos())
self.textInserted.emit(text_item)
else:
self.m_dragged = QGraphicsScene.itemAt(self, mouse_event.scenePos(), QTransform())
if self.m_dragged:
self.my_mode = self.MoveItem
self.m_drag_offset = mouse_event.scenePos() - self.m_dragged.pos()
super(DiagramScene, self).mousePressEvent(mouse_event)
示例2: Overview
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsScene [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsScene import itemAt [as 别名]
#.........这里部分代码省略.........
self.scene.removeItem(rect)
self.idx_annot = []
if self.parent.notes.annot is None:
return
bookmarks = []
events = []
if self.parent.value('annot_show'):
bookmarks = self.parent.notes.annot.get_bookmarks()
events = self.parent.notes.get_selected_events()
annotations = bookmarks + events
for annot in annotations:
rect = QGraphicsRectItem(annot['start'],
BARS['annot']['pos0'],
annot['end'] - annot['start'],
BARS['annot']['pos1'])
self.scene.addItem(rect)
if annot in bookmarks:
color = self.parent.value('annot_bookmark_color')
if annot in events:
color = convert_name_to_color(annot['name'])
rect.setPen(QPen(QColor(color), LINE_WIDTH))
rect.setBrush(QBrush(QColor(color)))
rect.setZValue(-5)
self.idx_annot.append(rect)
for epoch in self.parent.notes.annot.epochs:
self.mark_stages(epoch['start'],
epoch['end'] - epoch['start'],
epoch['stage'])
def mark_stages(self, start_time, length, stage_name):
"""Mark stages, only add the new ones.
Parameters
----------
start_time : int
start time in s of the epoch being scored.
length : int
duration in s of the epoch being scored.
stage_name : str
one of the stages defined in global stages.
"""
y_pos = BARS['stage']['pos0']
# the -1 is really important, otherwise we stay on the edge of the rect
old_score = self.scene.itemAt(start_time + length / 2,
y_pos +
STAGES[stage_name]['pos0'] +
STAGES[stage_name]['pos1'] - 1,
self.transform())
# check we are not removing the black border
if old_score is not None and old_score.pen() == NoPen:
lg.debug('Removing old score at {}'.format(start_time))
self.scene.removeItem(old_score)
self.idx_annot.remove(old_score)
rect = QGraphicsRectItem(start_time,
y_pos + STAGES[stage_name]['pos0'],
length,
STAGES[stage_name]['pos1'])
rect.setPen(NoPen)
rect.setBrush(STAGES[stage_name]['color'])
self.scene.addItem(rect)
self.idx_annot.append(rect)
def mousePressEvent(self, event):
"""Jump to window when user clicks on overview.
Parameters
----------
event : instance of QtCore.QEvent
it contains the position that was clicked.
"""
if self.scene is not None:
x_in_scene = self.mapToScene(event.pos()).x()
window_length = self.parent.value('window_length')
window_start = int(floor(x_in_scene / window_length) *
window_length)
self.update_position(window_start)
def reset(self):
"""Reset the widget, and clear the scene."""
self.minimum = None
self.maximum = None
self.start_time = None # datetime, absolute start time
self.idx_current = None
self.idx_markers = []
self.idx_annot = []
if self.scene is not None:
self.scene.clear()
self.scene = None