Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

PoC: GUI-native crosshair cursor#30516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
timhoffm wants to merge2 commits intomatplotlib:main
base:main
Choose a base branch
Loading
fromtimhoffm:crosshair-cursor
Draft
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletionlib/matplotlib/backends/backend_qt.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
from collections import namedtuple
import functools
import os
import sys
Expand DownExpand Up@@ -213,6 +214,9 @@ def _timer_stop(self):
self._timer.stop()


Crosshair = namedtuple('Crosshair', 'x, y, x0, x1, y0, y1')


class FigureCanvasQT(FigureCanvasBase, QtWidgets.QWidget):
required_interactive_framework = "qt"
_timer_cls = TimerQT
Expand All@@ -231,6 +235,7 @@ class FigureCanvasQT(FigureCanvasBase, QtWidgets.QWidget):
def __init__(self, figure=None):
_create_qApp()
super().__init__(figure=figure)
self._crosshair = None

self._draw_pending = False
self._is_drawing = False
Expand DownExpand Up@@ -305,6 +310,21 @@ def mouseEventCoords(self, pos=None):
y = self.figure.bbox.height / self.device_pixel_ratio - pos.y()
return x * self.device_pixel_ratio, y * self.device_pixel_ratio

def _update_crosshair(self, x, y):
previous_crosshair = self._crosshair
ax = self.inaxes((x, y))
if ax is None:
self._crosshair = None
else:
bbox = ax.get_position() # in figure coords
x0 = int(bbox.x0 * self.width())
x1 = int(bbox.x1 * self.width())
y0 = int((1 - bbox.y0) * self.height())
y1 = int((1 - bbox.y1) * self.height())
self._crosshair = Crosshair(x, y, x0, x1, y0, y1)
needs_repaint = previous_crosshair is not None or self._crosshair is not None
return needs_repaint

def enterEvent(self, event):
# Force querying of the modifiers, as the cached modifier state can
# have been invalidated while the window was out of focus.
Expand DownExpand Up@@ -344,8 +364,12 @@ def mouseDoubleClickEvent(self, event):
def mouseMoveEvent(self, event):
if self.figure is None:
return
mouse_xy = self.mouseEventCoords(event)
needs_repaint = self._update_crosshair(*mouse_xy)
if needs_repaint:
self.repaint()
MouseEvent("motion_notify_event", self,
*self.mouseEventCoords(event),
*mouse_xy,
buttons=self._mpl_buttons(event.buttons()),
modifiers=self._mpl_modifiers(),
guiEvent=event)._process()
Expand Down
11 changes: 11 additions & 0 deletionslib/matplotlib/backends/backend_qtagg.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -68,6 +68,17 @@ def paintEvent(self, event):
ctypes.c_long.from_address(id(buf)).value = 1

self._draw_rect_callback(painter)

if self._crosshair is not None:
x = self._crosshair.x
y = rect.height() - int(self._crosshair.y)
x0 = rect.left() + self._crosshair.x0
x1 = rect.left() + self._crosshair.x1
y0 = rect.top() + self._crosshair.y0
y1 = rect.top() + self._crosshair.y1
painter.setPen(QtGui.QPen(QtCore.Qt.GlobalColor.red))
painter.drawLine(x0, y, x1, y)
painter.drawLine(x, y0, x, y1)
finally:
painter.end()

Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp