Skip to content

feat: Add support for native gestures to enable pinch-to-zoom functionality#64

Merged
duartebarbosadev merged 3 commits intomainfrom
feat-touchpad-gestures
Dec 11, 2025
Merged

feat: Add support for native gestures to enable pinch-to-zoom functionality#64
duartebarbosadev merged 3 commits intomainfrom
feat-touchpad-gestures

Conversation

@duartebarbosadev
Copy link
Copy Markdown
Owner

This pull request adds support for native gesture events, specifically enabling pinch-to-zoom functionality using trackpads, to the AdvancedImageViewer UI component. The main change is the introduction of an overridden event method that handles QNativeGestureEvent instances, allowing users to zoom in and out with native gestures.

Gesture support improvements:

  • Added import of QNativeGestureEvent from PyQt6.QtGui to enable handling of native gesture events.
  • Implemented the event method to handle pinch-to-zoom gestures (ZoomNativeGesture), updating the zoom factor based on gesture input and anchoring the zoom to the gesture center for a more intuitive user experience.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds native gesture support to enable pinch-to-zoom functionality for the ZoomableImageView component, allowing users to zoom in and out using trackpad gestures.

  • Imported QNativeGestureEvent from PyQt6.QtGui
  • Implemented an event method override to handle ZoomNativeGesture events
  • Applied zoom factor changes with gesture-centered anchoring for intuitive zooming experience

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +113 to +114
event.accept()
return True
Copy link

Copilot AI Nov 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The event is accepted and returned as handled even when scale_delta <= 0 and no zoom operation is performed. Following Qt best practices, events should only be accepted when actually processed. Consider moving event.accept() and return True inside the if scale_delta > 0 block:

if scale_delta > 0:
    # Map the gesture center (global) into scene coordinates for precise anchoring
    gesture_pos_viewport = self.viewport().mapFromGlobal(
        event.globalPosition().toPoint()
    )
    center_point = self.mapToScene(gesture_pos_viewport)
    self.set_zoom_factor(self._zoom_factor * scale_delta, center_point)
    event.accept()
    return True
Suggested change
event.accept()
return True
event.accept()
return True

Copilot uses AI. Check for mistakes.
duartebarbosadev and others added 2 commits November 18, 2025 05:29
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@duartebarbosadev duartebarbosadev merged commit 69b50a6 into main Dec 11, 2025
3 checks passed
@duartebarbosadev duartebarbosadev deleted the feat-touchpad-gestures branch December 11, 2025 02:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants