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