Python PyQt5.QtGui.QMouseEvent() Examples
The following are 30 code examples for showing how to use PyQt5.QtGui.QMouseEvent(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
You may check out the related API usage on the sidebar.
You may also want to check out all available functions/classes of the module
PyQt5.QtGui
, or try the search function
.
Example 1
Project: track Author: frans-fuerst File: mainwindow.py License: Apache License 2.0 | 7 votes |
def event(self, e): if not isinstance(e, ( QtCore.QEvent, QtCore.QChildEvent, QtCore.QDynamicPropertyChangeEvent, QtGui.QPaintEvent, QtGui.QHoverEvent, QtGui.QMoveEvent, QtGui.QEnterEvent, QtGui.QResizeEvent, QtGui.QShowEvent, QtGui.QPlatformSurfaceEvent, QtGui.QWindowStateChangeEvent, QtGui.QKeyEvent, QtGui.QWheelEvent, QtGui.QMouseEvent, QtGui.QFocusEvent, QtGui.QHelpEvent, QtGui.QHideEvent, QtGui.QCloseEvent, QtGui.QInputMethodQueryEvent, QtGui.QContextMenuEvent, )): log().warning("unknown event: %r %r", e.type(), e) return super().event(e)
Example 2
Project: nanovna-saver Author: NanoVNA-Saver File: Chart.py License: GNU General Public License v3.0 | 6 votes |
def mousePressEvent(self, event: QtGui.QMouseEvent) -> None: if event.buttons() == QtCore.Qt.RightButton: event.ignore() return if event.buttons() == QtCore.Qt.MiddleButton: # Drag event event.accept() self.moveStartX = event.x() self.moveStartY = event.y() return if event.modifiers() == QtCore.Qt.ShiftModifier: self.draggedMarker = self.getNearestMarker(event.x(), event.y()) elif event.modifiers() == QtCore.Qt.ControlModifier: event.accept() self.draggedBox = True self.draggedBoxStart = (event.x(), event.y()) return self.mouseMoveEvent(event)
Example 3
Project: qutebrowser Author: qutebrowser File: webelem.py License: GNU General Public License v3.0 | 5 votes |
def _click_fake_event(self, click_target: usertypes.ClickTarget, button: Qt.MouseButton = Qt.LeftButton) -> None: """Send a fake click event to the element.""" pos = self._mouse_pos() log.webelem.debug("Sending fake click to {!r} at position {} with " "target {}".format(self, pos, click_target)) target_modifiers = { usertypes.ClickTarget.normal: Qt.NoModifier, usertypes.ClickTarget.window: Qt.AltModifier | Qt.ShiftModifier, usertypes.ClickTarget.tab: Qt.ControlModifier, usertypes.ClickTarget.tab_bg: Qt.ControlModifier, } if config.val.tabs.background: target_modifiers[usertypes.ClickTarget.tab] |= Qt.ShiftModifier else: target_modifiers[usertypes.ClickTarget.tab_bg] |= Qt.ShiftModifier modifiers = typing.cast(Qt.KeyboardModifiers, target_modifiers[click_target]) events = [ QMouseEvent(QEvent.MouseMove, pos, Qt.NoButton, Qt.NoButton, Qt.NoModifier), QMouseEvent(QEvent.MouseButtonPress, pos, button, button, modifiers), QMouseEvent(QEvent.MouseButtonRelease, pos, button, Qt.NoButton, modifiers), ] for evt in events: self._tab.send_event(evt) QTimer.singleShot(0, self._move_text_cursor)
Example 4
Project: qutebrowser Author: qutebrowser File: webelem.py License: GNU General Public License v3.0 | 5 votes |
def hover(self) -> None: """Simulate a mouse hover over the element.""" pos = self._mouse_pos() event = QMouseEvent(QEvent.MouseMove, pos, Qt.NoButton, Qt.NoButton, Qt.NoModifier) self._tab.send_event(event)
Example 5
Project: kawaii-player Author: kanishka-linux File: mpv_opengl.py License: GNU General Public License v3.0 | 5 votes |
def send_fake_event(self, val): self.fake_mousemove_event = ("libmpv", True) pos = self.cursor().pos() if not self.pointer_moved: new_point = QtCore.QPoint(pos.x() + 1, pos.y()) self.pointer_moved = True else: new_point = QtCore.QPoint(pos.x() - 1, pos.y()) self.pointer_moved = False self.cursor().setPos(new_point) if val == "mouse_release": event = QtGui.QMouseEvent( QtCore.QEvent.MouseButtonRelease, new_point, QtCore.Qt.LeftButton, QtCore.Qt.LeftButton, QtCore.Qt.NoModifier, ) elif val == "mouse_move": event = QtGui.QMouseEvent( QtCore.QEvent.MouseMove, new_point, QtCore.Qt.NoButton, QtCore.Qt.NoButton, QtCore.Qt.NoModifier, ) self.ui.gui_signals.mouse_move_method((self, event))
Example 6
Project: imperialism-remake Author: Trilarion File: qt.py License: GNU General Public License v3.0 | 5 votes |
def make_widget_clickable(parent): """ Takes any QtWidgets.QWidget derived class and emits a signal emitting on mousePressEvent. """ # noinspection PyPep8Naming class ClickableWidgetSubclass(parent): """ A widget that emits a clicked signal when the mouse is pressed. """ #: signal clicked = QtCore.pyqtSignal(QtGui.QMouseEvent) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) def mousePressEvent(self, event): # noqa: N802 """ Mouse has been pressed, process the event, then emit the signal. :param event: """ super().mousePressEvent(event) self.clicked.emit(event) return ClickableWidgetSubclass
Example 7
Project: vidcutter Author: ozmartian File: widgets.py License: GNU General Public License v3.0 | 5 votes |
def mousePressEvent(self, event: QMouseEvent) -> None: if event.button() == Qt.LeftButton: self.triggered.emit() super(VCFilterMenuAction.VCFilterMenuWidget, self).mousePressEvent(event)
Example 8
Project: vidcutter Author: ozmartian File: mpvwidget.py License: GNU General Public License v3.0 | 5 votes |
def mousePressEvent(self, event: QMouseEvent) -> None: event.accept() if event.button() == Qt.LeftButton: if self.parent is None: self.originalParent.playMedia() else: self.parent.playMedia()
Example 9
Project: vidcutter Author: ozmartian File: mpvwidget.py License: GNU General Public License v3.0 | 5 votes |
def mouseDoubleClickEvent(self, event: QMouseEvent) -> None: event.accept() if self.parent is None: self.originalParent.toggleFullscreen() else: self.parent.toggleFullscreen()
Example 10
Project: vidcutter Author: ozmartian File: notifications.py License: GNU General Public License v3.0 | 5 votes |
def mousePressEvent(self, event: QMouseEvent): if event.button() == Qt.LeftButton: self.close()
Example 11
Project: vidcutter Author: ozmartian File: videoslider.py License: GNU General Public License v3.0 | 5 votes |
def keyPressEvent(self, event: QKeyEvent) -> None: qApp.sendEvent(self.parent, event) # def mouseMoveEvent(self, event: QMouseEvent) -> None: # opt = QStyleOptionSlider() # self.initStyleOption(opt) # handle = self.style().subControlRect(QStyle.CC_Slider, opt, QStyle.SC_SliderHandle, self) # if handle.x() <= event.pos().x() <= (handle.x() + handle.width()): # self.setCursor(Qt.PointingHandCursor) # self._handleHover = True # else: # self.unsetCursor() # self._handleHover = False # self.initStyle() # super(VideoSlider, self).mouseMoveEvent(event)
Example 12
Project: vidcutter Author: ozmartian File: mediastream.py License: GNU General Public License v3.0 | 5 votes |
def mousePressEvent(self, event: QMouseEvent) -> None: if event.button() == Qt.LeftButton and self.checkbox is not None: self.checkbox.toggle() super(StreamSelectorLabel, self).mousePressEvent(event)
Example 13
Project: vidcutter Author: ozmartian File: videolist.py License: GNU General Public License v3.0 | 5 votes |
def mouseMoveEvent(self, event: QMouseEvent) -> None: if self.count() > 0: if self.indexAt(event.pos()).isValid(): self.setCursor(Qt.PointingHandCursor) else: self.setCursor(Qt.ArrowCursor) super(VideoList, self).mouseMoveEvent(event)
Example 14
Project: nanovna-saver Author: NanoVNA-Saver File: Polar.py License: GNU General Public License v3.0 | 5 votes |
def mouseMoveEvent(self, a0: QtGui.QMouseEvent) -> None: if a0.buttons() == QtCore.Qt.RightButton: a0.ignore() return x = a0.x() y = a0.y() absx = x - (self.width() - self.chartWidth) / 2 absy = y - (self.height() - self.chartHeight) / 2 if absx < 0 or absx > self.chartWidth or absy < 0 or absy > self.chartHeight \ or len(self.data) == len(self.reference) == 0: a0.ignore() return a0.accept() if len(self.data) > 0: target = self.data else: target = self.reference positions = [] for d in target: thisx = self.width() / 2 + d.re * self.chartWidth / 2 thisy = self.height() / 2 + d.im * -1 * self.chartHeight / 2 positions.append(math.sqrt((x - thisx)**2 + (y - thisy)**2)) minimum_position = positions.index(min(positions)) m = self.getActiveMarker() if m is not None: m.setFrequency(str(round(target[minimum_position].freq))) m.frequencyInput.setText(str(round(target[minimum_position].freq))) return
Example 15
Project: nanovna-saver Author: NanoVNA-Saver File: Frequency.py License: GNU General Public License v3.0 | 5 votes |
def mouseMoveEvent(self, a0: QtGui.QMouseEvent): if a0.buttons() == QtCore.Qt.RightButton: a0.ignore() return if a0.buttons() == QtCore.Qt.MiddleButton: # Drag the display a0.accept() if self.moveStartX != -1 and self.moveStartY != -1: dx = self.moveStartX - a0.x() dy = self.moveStartY - a0.y() self.zoomTo(self.leftMargin + dx, self.topMargin + dy, self.leftMargin + self.chartWidth + dx, self.topMargin + self.chartHeight + dy) self.moveStartX = a0.x() self.moveStartY = a0.y() return if a0.modifiers() == QtCore.Qt.ControlModifier: # Dragging a box if not self.draggedBox: self.draggedBoxStart = (a0.x(), a0.y()) self.draggedBoxCurrent = (a0.x(), a0.y()) self.update() a0.accept() return x = a0.x() f = self.frequencyAtPosition(x) if x == -1: a0.ignore() return a0.accept() m = self.getActiveMarker() if m is not None: m.setFrequency(str(f)) m.frequencyInput.setText(str(f))
Example 16
Project: nanovna-saver Author: NanoVNA-Saver File: Smith.py License: GNU General Public License v3.0 | 5 votes |
def mouseMoveEvent(self, a0: QtGui.QMouseEvent) -> None: if a0.buttons() == QtCore.Qt.RightButton: a0.ignore() return x = a0.x() y = a0.y() absx = x - (self.width() - self.chartWidth) / 2 absy = y - (self.height() - self.chartHeight) / 2 if absx < 0 or absx > self.chartWidth or absy < 0 or absy > self.chartHeight \ or len(self.data) == len(self.reference) == 0: a0.ignore() return a0.accept() if len(self.data) > 0: target = self.data else: target = self.reference positions = [] for d in target: thisx = self.width() / 2 + d.re * self.chartWidth / 2 thisy = self.height() / 2 + d.im * -1 * self.chartHeight / 2 positions.append(math.sqrt((x - thisx)**2 + (y - thisy)**2)) minimum_position = positions.index(min(positions)) m = self.getActiveMarker() if m is not None: m.setFrequency(str(round(target[minimum_position].freq))) m.frequencyInput.setText(str(round(target[minimum_position].freq))) return
Example 17
Project: nanovna-saver Author: NanoVNA-Saver File: Chart.py License: GNU General Public License v3.0 | 5 votes |
def mouseReleaseEvent(self, a0: QtGui.QMouseEvent) -> None: self.draggedMarker = None if self.draggedBox: self.zoomTo(self.draggedBoxStart[0], self.draggedBoxStart[1], a0.x(), a0.y()) self.draggedBox = False self.draggedBoxCurrent = (-1, -1) self.draggedBoxStart = (0, 0) self.update()
Example 18
Project: FeelUOwn Author: feeluown File: songs.py License: GNU General Public License v3.0 | 5 votes |
def editorEvent(self, event, model, option, index): if event.type() in (QEvent.MouseButtonPress, QEvent.MouseButtonRelease): no_bottom_right = QPoint(self.number_rect_x, option.rect.bottom()) no_rect = QRect(option.rect.topLeft(), no_bottom_right) mouse_event = QMouseEvent(event) if no_rect.contains(mouse_event.pos()): if event.type() == QEvent.MouseButtonPress: self.play_btn_pressed = True if event.type() == QEvent.MouseButtonRelease: if self.play_btn_pressed is True: self.parent().play_song_needed.emit(index.data(Qt.UserRole)) if event.type() == QEvent.MouseButtonRelease: self.play_btn_pressed = False return super().editorEvent(event, model, option, index)
Example 19
Project: PyQt5 Author: andresnino File: barraTitulo.py License: MIT License | 5 votes |
def mouseReleaseEvent(self, QMouseEvent): self.pressing = False
Example 20
Project: PyQt5 Author: andresnino File: barraTitulo.py License: MIT License | 5 votes |
def mouseReleaseEvent(self, QMouseEvent): self.pressing = False
Example 21
Project: CNNArt Author: thomaskuestner File: gridTable.py License: Apache License 2.0 | 5 votes |
def mouseReleaseEvent(self, event: QMouseEvent): event.accept() if event.button() == 1: self.released.emit(event)
Example 22
Project: Hydra Author: CountryTk File: foldArea.py License: GNU General Public License v3.0 | 5 votes |
def mousePressEvent(self, event: QMouseEvent): pattern = re.compile(FOLDING_PATTERN) blockedClickedOn: QTextBlock = self.getBlockUnderCursor(event) if pattern.match(blockedClickedOn.text()): if blockedClickedOn.userState() == 0: # block and its contents are unfolded self.fold(blockedClickedOn) else: self.unfold(blockedClickedOn)
Example 23
Project: Hydra Author: CountryTk File: foldArea.py License: GNU General Public License v3.0 | 5 votes |
def getBlockUnderCursor(self, event: QMouseEvent) -> QTextBlock: height = self.editor.fontMetrics().height() y = event.pos().y() for array in self.editor.currentlyVisibleBlocks: if array[0] < y < height + array[0]: return array[1]
Example 24
Project: Hydra Author: CountryTk File: foldArea.py License: GNU General Public License v3.0 | 5 votes |
def mouseMoveEvent(self, event: QMouseEvent) -> None: pattern = re.compile(FOLDING_PATTERN) block: QTextBlock = self.editor.getBlockUnderCursor(event) if pattern.match(block.text()): cursor: QCursor = QCursor(Qt.PointingHandCursor) QApplication.setOverrideCursor(cursor) QApplication.changeOverrideCursor(cursor) else: self.returnCursorToNormal()
Example 25
Project: Hydra Author: CountryTk File: numberBar.py License: GNU General Public License v3.0 | 5 votes |
def mousePressEvent(self, event: QMouseEvent): pass
Example 26
Project: Hydra Author: CountryTk File: numberBar.py License: GNU General Public License v3.0 | 5 votes |
def getBlockUnderCursor(self, event: QMouseEvent) -> QTextBlock: height = self.editor.fontMetrics().height() y = event.pos().y() for array in self.editor.currentlyVisibleBlocks: print(array[0], y, height+array[0]) if array[0] < y < height + array[0]: return array[1]
Example 27
Project: CvStudio Author: haruiz File: switch_button.py License: MIT License | 5 votes |
def mousePressEvent(self, e: QMouseEvent) -> None: super(SwitchButton, self).mousePressEvent(e)
Example 28
Project: CvStudio Author: haruiz File: card.py License: MIT License | 5 votes |
def mouseDoubleClickEvent(self, evt: QtGui.QMouseEvent) -> None: if self.childAt(evt.pos()) == self.thumbnail.widget(): self.doubleClicked.emit(self)
Example 29
Project: CvStudio Author: haruiz File: card.py License: MIT License | 5 votes |
def mousePressEvent(self, evt: QtGui.QMouseEvent) -> None: if evt.button() == QtCore.Qt.LeftButton: if self.childAt(evt.pos()) == self.thumbnail.widget(): self.is_selected = not self.is_selected
Example 30
Project: CvStudio Author: haruiz File: image_dialog.py License: MIT License | 5 votes |
def mouseMoveEvent(self, event: QMouseEvent) -> None: # print('mouseMoveEvent: x=%d, y=%d' % (event.x(), event.y())) if not self.rect().contains(event.pos()): self.close()