Python PyQt5.QtGui.QMouseEvent() Examples

The following are 30 code examples of PyQt5.QtGui.QMouseEvent(). 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 also want to check out all available functions/classes of the module PyQt5.QtGui , or try the search function .
Example #1
Source File: mpv_opengl.py    From kawaii-player with GNU General Public License v3.0 11 votes vote down vote up
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 #2
Source File: mainwindow.py    From track with Apache License 2.0 11 votes vote down vote up
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 #3
Source File: widgets.py    From vidcutter with GNU General Public License v3.0 10 votes vote down vote up
def mousePressEvent(self, event: QMouseEvent) -> None:
            if event.button() == Qt.LeftButton:
                self.triggered.emit()
            super(VCFilterMenuAction.VCFilterMenuWidget, self).mousePressEvent(event) 
Example #4
Source File: mpvwidget.py    From vidcutter with GNU General Public License v3.0 10 votes vote down vote up
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 #5
Source File: qt.py    From imperialism-remake with GNU General Public License v3.0 9 votes vote down vote up
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 #6
Source File: webelem.py    From qutebrowser with GNU General Public License v3.0 8 votes vote down vote up
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 #7
Source File: mpvwidget.py    From vidcutter with GNU General Public License v3.0 8 votes vote down vote up
def mouseDoubleClickEvent(self, event: QMouseEvent) -> None:
        event.accept()
        if self.parent is None:
            self.originalParent.toggleFullscreen()
        else:
            self.parent.toggleFullscreen() 
Example #8
Source File: notifications.py    From vidcutter with GNU General Public License v3.0 8 votes vote down vote up
def mousePressEvent(self, event: QMouseEvent):
        if event.button() == Qt.LeftButton:
            self.close() 
Example #9
Source File: Chart.py    From nanovna-saver with GNU General Public License v3.0 8 votes vote down vote up
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 #10
Source File: foldArea.py    From Hydra with GNU General Public License v3.0 7 votes vote down vote up
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 #11
Source File: webelem.py    From qutebrowser with GNU General Public License v3.0 7 votes vote down vote up
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 #12
Source File: foldArea.py    From Hydra with GNU General Public License v3.0 7 votes vote down vote up
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 #13
Source File: foldArea.py    From Hydra with GNU General Public License v3.0 7 votes vote down vote up
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 #14
Source File: numberBar.py    From Hydra with GNU General Public License v3.0 7 votes vote down vote up
def mousePressEvent(self, event: QMouseEvent):
        pass 
Example #15
Source File: numberBar.py    From Hydra with GNU General Public License v3.0 7 votes vote down vote up
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 #16
Source File: switch_button.py    From CvStudio with MIT License 7 votes vote down vote up
def mousePressEvent(self, e: QMouseEvent) -> None:
        super(SwitchButton, self).mousePressEvent(e) 
Example #17
Source File: card.py    From CvStudio with MIT License 7 votes vote down vote up
def mouseDoubleClickEvent(self, evt: QtGui.QMouseEvent) -> None:
        if self.childAt(evt.pos()) == self.thumbnail.widget():
            self.doubleClicked.emit(self) 
Example #18
Source File: card.py    From CvStudio with MIT License 7 votes vote down vote up
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 #19
Source File: image_dialog.py    From CvStudio with MIT License 7 votes vote down vote up
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() 
Example #20
Source File: barraTitulo.py    From PyQt5 with MIT License 7 votes vote down vote up
def mouseReleaseEvent(self, QMouseEvent):
        self.pressing = False 
Example #21
Source File: videoslider.py    From vidcutter with GNU General Public License v3.0 7 votes vote down vote up
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 #22
Source File: mediastream.py    From vidcutter with GNU General Public License v3.0 7 votes vote down vote up
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 #23
Source File: videolist.py    From vidcutter with GNU General Public License v3.0 7 votes vote down vote up
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 #24
Source File: Polar.py    From nanovna-saver with GNU General Public License v3.0 7 votes vote down vote up
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 #25
Source File: Frequency.py    From nanovna-saver with GNU General Public License v3.0 7 votes vote down vote up
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 #26
Source File: Smith.py    From nanovna-saver with GNU General Public License v3.0 7 votes vote down vote up
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 #27
Source File: Chart.py    From nanovna-saver with GNU General Public License v3.0 7 votes vote down vote up
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 #28
Source File: songs.py    From FeelUOwn with GNU General Public License v3.0 7 votes vote down vote up
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 #29
Source File: barraTitulo.py    From PyQt5 with MIT License 7 votes vote down vote up
def mouseReleaseEvent(self, QMouseEvent):
        self.pressing = False 
Example #30
Source File: gridTable.py    From CNNArt with Apache License 2.0 6 votes vote down vote up
def mouseReleaseEvent(self, event: QMouseEvent):
        event.accept()
        if event.button() == 1:
            self.released.emit(event)