我们从Python开源项目中,提取了以下14个代码示例,用于说明如何使用PyQt5.QtGui.QMouseEvent()。
def mousePressEvent(self, event: QMouseEvent) -> None: if event.button() == Qt.LeftButton and self.cutter.mediaAvailable: self.cutter.cliplist.clearSelection() self.cutter.timeCounter.clearFocus() self.cutter.frameCounter.clearFocus() # noinspection PyBroadException try: if hasattr(self.cutter, 'notify'): self.cutter.notify.fadeOut() except BaseException: pass
def eventFilter(self, obj: QObject, event: QMouseEvent) -> bool: if event.type() == QEvent.MouseButtonRelease and event.button() == Qt.LeftButton: if self.parent.mediaAvailable and self.isEnabled(): newpos = QStyle.sliderValueFromPosition(self.minimum(), self.maximum(), event.x() - self.offset, self.width() - (self.offset * 2)) self.setValue(newpos) self.parent.setPosition(newpos) self.parent.parent.mousePressEvent(event) return super(VideoSlider, self).eventFilter(obj, event)
def mousePressEvent(self, event: QMouseEvent): if event.button() == Qt.LeftButton: self.fadeOut() # noinspection PyTypeChecker
def mouseDoubleClickEvent(self, event: QMouseEvent) -> None: event.accept() if self.isFullScreen(): self._exitFullScreen() self.parent.toggleFullscreen() # super(mpvWidget, self).mouseDoubleClickEvent(event)
def mouseMoveEvent(self, event: QMouseEvent) -> None: if self.count() > 0: modelindex = self.indexAt(event.pos()) if modelindex.isValid(): self.setCursor(Qt.PointingHandCursor) else: self.setCursor(Qt.ArrowCursor) super(VideoList, self).mouseMoveEvent(event)
def mouseMoveEvent(self, event: QMouseEvent): self.scene().mousePos = event.pos()
def mousePressEvent(self, ev: QtGui.QMouseEvent): self._do_heavy_highlight = True self._highlightClear() super(VQMemoryCanvas, self).mousePressEvent(ev)
def mouseDoubleClickEvent(self, ev: QtGui.QMouseEvent): # super(VQMemoryCanvas, self).mouseDoubleClickEvent(ev) t = self.cursorForPosition(ev.pos()) cf = t.charFormat() tag = cf.property(VivTextProperties.vivTag) val = cf.property(VivTextProperties.vivValue) if tag is ContentTagsEnum.VA: self.gotoVa(val) else: if self._hasHighligtedTags() is True: self._highlightClear() self._highlightTag(tag, val)
def mouseReleaseEvent(self, event: QMouseEvent): if self.scene() is None: return cursor = self.cursor().shape() if cursor == Qt.ClosedHandCursor: self.grab_start = None self.setCursor(Qt.OpenHandCursor) elif self.separation_area_moving: y_sep = self.mapToScene(event.pos()).y() y = self.sceneRect().y() h = self.sceneRect().height() if y_sep < y: y_sep = y elif y_sep > y + h: y_sep = y + h self.scene().draw_sep_area(y_sep) self.sep_area_moving.emit(y_sep) self.separation_area_moving = False self.y_sep = y_sep self.sep_area_changed.emit(-y_sep) self.unsetCursor() self.selection_area.finished = True self.selection_area.resizing = False self.emit_selection_size_changed() self.emit_selection_start_end_changed()
def mouseMoveEvent(self, event: QMouseEvent): super().mouseMoveEvent(event) if isinstance(self.scene(), GridScene): x = int(self.mapToScene(event.pos()).x()) freq = self.scene().get_freq_for_pos(x) self.scene().draw_frequency_marker(x, freq)
def mousePressEvent(self, event: QMouseEvent): if isinstance(self.scene(), GridScene): freq = self.scene().get_freq_for_pos(int(self.mapToScene(event.pos()).x())) if freq is not None: self.freq_clicked.emit(freq)
def mousePressEvent(self, event): assert isinstance(event, QMouseEvent) if len(self.text()) == 0: if event.button() == Qt.LeftButton: self.openExplorer() super().mousePressEvent(event)
def test_spectrum(self): port = self.__get_free_port() spectrum_dialog = self.__get_spectrum_dialog() spectrum_dialog.device.set_server_port(port) spectrum_dialog.ui.btnStart.click() self.assertEqual(len(spectrum_dialog.scene_manager.peak), 0) data = np.array([complex(1, 1), complex(2, 2), complex(3, 3)], dtype=np.complex64) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.connect(("127.0.0.1", port)) sock.sendall(data.tostring()) sock.shutdown(socket.SHUT_RDWR) sock.close() QApplication.instance().processEvents() QTest.qWait(self.SEND_RECV_TIMEOUT) self.assertGreater(len(spectrum_dialog.scene_manager.peak), 0) self.assertIsNone(spectrum_dialog.ui.graphicsViewFFT.scene().frequency_marker) w = spectrum_dialog.ui.graphicsViewFFT.viewport() # this actually gets the click to the view # QTest.mouseMove(w, QPoint(80,80)) event = QMouseEvent(QEvent.MouseMove, QPoint(80, 80), w.mapToGlobal(QPoint(80, 80)), Qt.LeftButton, Qt.LeftButton, Qt.NoModifier) QApplication.postEvent(w, event) QApplication.instance().processEvents() self.assertIsNotNone(spectrum_dialog.ui.graphicsViewFFT.scene().frequency_marker) spectrum_dialog.ui.btnStop.click() self.assertGreater(len(spectrum_dialog.ui.graphicsViewSpectrogram.items()), 0) spectrum_dialog.ui.btnClear.click() self.assertEqual(len(spectrum_dialog.ui.graphicsViewSpectrogram.items()), 0) self.__close_dialog(spectrum_dialog)
def mousePressEvent(self, event: QMouseEvent): if self.scene() is None: return cursor = self.cursor().shape() has_shift_modifier = event.modifiers() == Qt.ShiftModifier is_in_shift_mode = (has_shift_modifier and self.hold_shift_to_drag) \ or (not has_shift_modifier and not self.hold_shift_to_drag) \ and cursor != Qt.SplitHCursor and cursor != Qt.SplitVCursor if event.buttons() == Qt.LeftButton and is_in_shift_mode: self.setCursor(Qt.ClosedHandCursor) self.grab_start = event.pos() elif event.buttons() == Qt.LeftButton: if self.is_pos_in_separea(self.mapToScene(event.pos())): self.separation_area_moving = True self.setCursor(Qt.SplitVCursor) elif self.selection_area.is_empty or self.selection_area.selected_edge is None: # Create new selection self.mouse_press_pos = event.pos() self.mouse_pos = event.pos() scene_pos = self.mapToScene(self.mouse_press_pos) self.__set_selection_area(x=scene_pos.x(), y=scene_pos.y(), w=0, h=0) self.selection_area.finished = False elif self.selection_area.selected_edge is not None: self.selection_area.resizing = True