pyclickimage.ImageViewer#

class pyclickimage.ImageViewer(parent=None, half_shift=True)[source]#

Bases: QGraphicsView

Interactive image viewer with: - subpixel cursor tracking - crosshair overlay - zoom with mouse wheel - precise click detection (drag-safe) - marker system for annotation

half-shift :

  • True = (0,0) on the center of the first pixel.

  • False = (0,0) on the corner of the first pixel.

add_marker(center: ~typing.Tuple[float, float], color: ~PyQt5.QtGui.QColor = <PyQt5.QtGui.QColor object>, size: int = 8) None[source]#

Add a cross-style marker at a given position.

Parameters:
  • center (Tuple[float, float]) – (x, y) coordinates.

  • color (QtGui.QColor) – Marker color.

  • size (int) – Half-size of cross arms.

clear_markers() None[source]#

Remove all markers from the scene.

get_crosshair_color() QColor[source]#

Return current crosshair color.

left_click_signal#
load_image(path: str) None[source]#

Load an image into the viewer.

Parameters:

path (str) – Path to image file.

Raises:

ValueError – If image cannot be loaded.

mouseMoveEvent(event: QMouseEvent) None[source]#

Update crosshair and coordinate display.

Parameters:

event (QtGui.QMouseEvent) – Mouse move event.

mousePressEvent(event: QMouseEvent) None[source]#

Store press position for click validation.

Parameters:

event (QtGui.QMouseEvent) – Mouse press event.

mouseReleaseEvent(event: QMouseEvent) None[source]#

Detect valid click and emit coordinates.

Parameters:

event (QtGui.QMouseEvent) – Mouse release event.

reset_view() None[source]#

Reset the view to the initial state (no zoom, centered image).

This method: - resets the internal zoom counter - resets Qt transformation matrix - re-applies fitInView on the current image

right_click_signal#
set_crosshair_color(color)[source]#

Set the crosshair color

set_image(pixmap: QPixmap)[source]#

Set the displayed image in the viewer.

Parameters:

pixmap (QtGui.QPixmap) – Image already converted for Qt display.

wheelEvent(event: QWheelEvent) None[source]#

Handle zoom with mouse wheel.

Parameters:

event (QtGui.QWheelEvent) – Wheel event.