Scrollen mit der Linker Maustaste
This commit is contained in:
@@ -32,6 +32,12 @@ class MainWindow(QMainWindow):
|
|||||||
# Aktueller Zoom-Faktor
|
# Aktueller Zoom-Faktor
|
||||||
self.current_zoom = 100 # 100%
|
self.current_zoom = 100 # 100%
|
||||||
|
|
||||||
|
# Variablen für Drag-to-Scroll (Anti-Jitter für 4K/DPI-Skalierung)
|
||||||
|
self.is_dragging = False
|
||||||
|
self.last_drag_position = None
|
||||||
|
self.drag_threshold = 3 # Mindestbewegung in Pixeln vor dem Scrollen
|
||||||
|
self.scroll_sensitivity = 0.7 # Reduzierte Empfindlichkeit für sanfteres Scrollen
|
||||||
|
|
||||||
# Bilder laden
|
# Bilder laden
|
||||||
self._load_images()
|
self._load_images()
|
||||||
|
|
||||||
@@ -98,6 +104,11 @@ class MainWindow(QMainWindow):
|
|||||||
# Click-Event für das Thumbnail einrichten
|
# Click-Event für das Thumbnail einrichten
|
||||||
thumbnail.mousePressEvent = lambda event, t=thumbnail: self.on_thumbnail_clicked(event, t)
|
thumbnail.mousePressEvent = lambda event, t=thumbnail: self.on_thumbnail_clicked(event, t)
|
||||||
|
|
||||||
|
# Drag-to-Scroll Events für große Bilder einrichten
|
||||||
|
fullsize.mousePressEvent = lambda event, f=fullsize: self.on_fullsize_mouse_press(event, f)
|
||||||
|
fullsize.mouseMoveEvent = lambda event, f=fullsize: self.on_fullsize_mouse_move(event, f)
|
||||||
|
fullsize.mouseReleaseEvent = lambda event, f=fullsize: self.on_fullsize_mouse_release(event, f)
|
||||||
|
|
||||||
# PDF-Dokument schließen
|
# PDF-Dokument schließen
|
||||||
pdf_document.close()
|
pdf_document.close()
|
||||||
|
|
||||||
@@ -162,3 +173,63 @@ class MainWindow(QMainWindow):
|
|||||||
|
|
||||||
# Stelle sicher, dass die horizontale Zentrierung beibehalten wird
|
# Stelle sicher, dass die horizontale Zentrierung beibehalten wird
|
||||||
fullsize_label.setAlignment(Qt.AlignmentFlag.AlignHCenter)
|
fullsize_label.setAlignment(Qt.AlignmentFlag.AlignHCenter)
|
||||||
|
|
||||||
|
def on_fullsize_mouse_press(self, event, fullsize_label):
|
||||||
|
"""
|
||||||
|
Wird ausgeführt, wenn die Maustaste auf einem großen Bild gedrückt wird.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
event: Das Maus-Event
|
||||||
|
fullsize_label: Das große Bild-Label
|
||||||
|
"""
|
||||||
|
if event.button() == Qt.MouseButton.LeftButton:
|
||||||
|
self.is_dragging = True
|
||||||
|
# Verwende globale Position für bessere 4K/DPI Kompatibilität
|
||||||
|
self.last_drag_position = event.globalPosition().toPoint()
|
||||||
|
fullsize_label.setCursor(QCursor(Qt.CursorShape.ClosedHandCursor))
|
||||||
|
|
||||||
|
def on_fullsize_mouse_move(self, event, fullsize_label):
|
||||||
|
"""
|
||||||
|
Wird ausgeführt, wenn die Maus über einem großen Bild bewegt wird.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
event: Das Maus-Event
|
||||||
|
fullsize_label: Das große Bild-Label
|
||||||
|
"""
|
||||||
|
if self.is_dragging and self.last_drag_position is not None:
|
||||||
|
# Verwende globale Position für bessere 4K/DPI Kompatibilität
|
||||||
|
current_pos = event.globalPosition().toPoint()
|
||||||
|
delta = current_pos - self.last_drag_position
|
||||||
|
|
||||||
|
# Prüfe ob die Bewegung groß genug ist (Anti-Jitter)
|
||||||
|
if abs(delta.x()) >= self.drag_threshold or abs(delta.y()) >= self.drag_threshold:
|
||||||
|
# Hole die aktuellen Scroll-Balken
|
||||||
|
v_scrollbar = self.ui.scrollArea_2.verticalScrollBar()
|
||||||
|
h_scrollbar = self.ui.scrollArea_2.horizontalScrollBar()
|
||||||
|
|
||||||
|
# Berechne neue Scroll-Positionen mit reduzierter Empfindlichkeit
|
||||||
|
scroll_delta_y = int(-delta.y() * self.scroll_sensitivity)
|
||||||
|
scroll_delta_x = int(-delta.x() * self.scroll_sensitivity)
|
||||||
|
|
||||||
|
new_v_value = v_scrollbar.value() + scroll_delta_y
|
||||||
|
new_h_value = h_scrollbar.value() + scroll_delta_x
|
||||||
|
|
||||||
|
# Setze die neuen Scroll-Positionen
|
||||||
|
v_scrollbar.setValue(new_v_value)
|
||||||
|
h_scrollbar.setValue(new_h_value)
|
||||||
|
|
||||||
|
# Aktualisiere die letzte Position nur bei erfolgreichem Scroll
|
||||||
|
self.last_drag_position = current_pos
|
||||||
|
|
||||||
|
def on_fullsize_mouse_release(self, event, fullsize_label):
|
||||||
|
"""
|
||||||
|
Wird ausgeführt, wenn die Maustaste auf einem großen Bild losgelassen wird.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
event: Das Maus-Event
|
||||||
|
fullsize_label: Das große Bild-Label
|
||||||
|
"""
|
||||||
|
if event.button() == Qt.MouseButton.LeftButton:
|
||||||
|
self.is_dragging = False
|
||||||
|
self.last_drag_position = None
|
||||||
|
fullsize_label.setCursor(QCursor(Qt.CursorShape.ArrowCursor))
|
||||||
|
|||||||
Reference in New Issue
Block a user