feat: Add support for native gestures to enable pinch-to-zoom functionality#64
Merged
duartebarbosadev merged 3 commits intomainfrom Dec 11, 2025
Merged
feat: Add support for native gestures to enable pinch-to-zoom functionality#64duartebarbosadev merged 3 commits intomainfrom
duartebarbosadev merged 3 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
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
QNativeGestureEventfrom PyQt6.QtGui - Implemented an
eventmethod override to handleZoomNativeGestureevents - 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 |
There was a problem hiding this comment.
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 |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request adds support for native gesture events, specifically enabling pinch-to-zoom functionality using trackpads, to the
AdvancedImageViewerUI component. The main change is the introduction of an overriddeneventmethod that handlesQNativeGestureEventinstances, allowing users to zoom in and out with native gestures.Gesture support improvements:
QNativeGestureEventfromPyQt6.QtGuito enable handling of native gesture events.eventmethod 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.