Fix galerie : miniatures remplissent les cartes, taille max limitée

- Miniature s'adapte à la taille de la carte via resizeEvent
- MaxWidth/MaxHeight sur les cartes pour éviter les cadres blancs énormes
- Fonctionne avec 3 ou 50 photos

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-21 23:12:17 +01:00
parent 380adef814
commit 9a643eadfc

View File

@@ -28,23 +28,19 @@ class PhotoCard(QFrame):
border-radius: 10px;
}
""")
self.setMaximumWidth(350)
self.setMaximumHeight(300)
layout = QVBoxLayout(self)
layout.setContentsMargins(5, 5, 5, 5)
layout.setContentsMargins(4, 4, 4, 4)
layout.setSpacing(4)
# Miniature
# Miniature — s'étire pour remplir la carte
self.thumb_label = QLabel()
self.thumb_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.thumb_label.setMinimumSize(150, 120)
pixmap = QPixmap(self.path)
if not pixmap.isNull():
scaled = pixmap.scaled(
200, 150,
Qt.AspectRatioMode.KeepAspectRatio,
Qt.TransformationMode.SmoothTransformation
)
self.thumb_label.setPixmap(scaled)
layout.addWidget(self.thumb_label)
self.thumb_label.setScaledContents(False)
self._pixmap_original = QPixmap(self.path)
layout.addWidget(self.thumb_label, 1)
# Barre du bas : crayon + quantité
bar = QHBoxLayout()
@@ -132,22 +128,31 @@ class PhotoCard(QFrame):
""")
self.qty_label.setStyleSheet("color: #333;")
def apply_responsive(self, window_height):
"""Adapte les tailles au responsive."""
thumb_h = max(80, int(window_height * 0.15))
thumb_w = max(100, int(thumb_h * 1.4))
self.thumb_label.setMinimumSize(thumb_w, thumb_h)
def resizeEvent(self, event):
super().resizeEvent(event)
self._update_thumbnail()
# Re-scale la miniature
pixmap = QPixmap(self.path)
if not pixmap.isNull():
scaled = pixmap.scaled(
thumb_w, thumb_h,
def _update_thumbnail(self):
"""Redimensionne la miniature pour remplir l'espace disponible."""
if self._pixmap_original.isNull():
return
w = self.thumb_label.width()
h = self.thumb_label.height()
if w > 10 and h > 10:
scaled = self._pixmap_original.scaled(
w, h,
Qt.AspectRatioMode.KeepAspectRatio,
Qt.TransformationMode.SmoothTransformation
)
self.thumb_label.setPixmap(scaled)
def apply_responsive(self, window_height):
"""Adapte les tailles au responsive."""
max_h = max(150, int(window_height * 0.28))
max_w = max(200, int(max_h * 1.3))
self.setMaximumHeight(max_h)
self.setMaximumWidth(max_w)
btn_size = max(28, int(window_height * 0.04))
font_size = max(12, int(window_height * 0.02))