From fd1db8c65aab81bbacbff7ae5975b5e94410b6a4 Mon Sep 17 00:00:00 2001 From: Boris Yumankulov Date: Thu, 3 Jul 2025 14:40:20 +0500 Subject: [PATCH] fix: elide overflowed badge text in ClickableLabel Signed-off-by: Boris Yumankulov --- portprotonqt/custom_widgets.py | 28 ++++++++++++-------- portprotonqt/themes/standart-light/styles.py | 3 --- portprotonqt/themes/standart/styles.py | 3 --- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/portprotonqt/custom_widgets.py b/portprotonqt/custom_widgets.py index 3e49196..65b72de 100644 --- a/portprotonqt/custom_widgets.py +++ b/portprotonqt/custom_widgets.py @@ -192,19 +192,26 @@ class ClickableLabel(QLabel): icon_size = self._icon_size spacing = self._icon_space - icon_rect = QRect() - text_rect = QRect() text = self.text() if self._icon: pixmap = self._icon.pixmap(icon_size, icon_size) - icon_rect = QRect(0, 0, icon_size, icon_size) - icon_rect.moveTop(rect.top() + (rect.height() - icon_size) // 2) else: pixmap = None fm = QFontMetrics(self.font()) - text_width = fm.horizontalAdvance(text) + + # Считаем, сколько места остаётся под текст + available_width = rect.width() + if pixmap: + available_width -= (icon_size + spacing) + # Отступы по 2px с каждой стороны + available_width = max(0, available_width - 4) + + # Получаем «обрезанный» текст с многоточием + display_text = fm.elidedText(text, Qt.TextElideMode.ElideRight, available_width) + + text_width = fm.horizontalAdvance(display_text) text_height = fm.height() total_width = text_width + (icon_size + spacing if pixmap else 0) @@ -214,24 +221,23 @@ class ClickableLabel(QLabel): x = rect.right() - total_width else: x = rect.left() - y = rect.top() + (rect.height() - text_height) // 2 if pixmap: - icon_rect.moveLeft(x) - text_rect = QRect(x + icon_size + spacing, y, text_width, text_height) + icon_rect = QRect(x, y + (text_height - icon_size) // 2, icon_size, icon_size) painter.drawPixmap(icon_rect, pixmap) + text_x = x + icon_size + spacing else: - # Устанавливаем text_rect для меток без иконки (например, favoriteLabel) - text_rect = QRect(x, y, text_width, text_height) + text_x = x + text_rect = QRect(text_x, y, text_width, text_height) self.style().drawItemText( painter, text_rect, alignment, self.palette(), self.isEnabled(), - text, + display_text, self.foregroundRole(), ) diff --git a/portprotonqt/themes/standart-light/styles.py b/portprotonqt/themes/standart-light/styles.py index 5af7283..7d3c378 100644 --- a/portprotonqt/themes/standart-light/styles.py +++ b/portprotonqt/themes/standart-light/styles.py @@ -480,7 +480,6 @@ def get_protondb_badge_style(tier): qproperty-alignment: AlignCenter; background-color: {colors["background"]}; color: {colors["color"]}; - font-size: 14px; border-radius: 5px; font-family: 'Poppins'; font-weight: bold; @@ -500,7 +499,6 @@ def get_anticheat_badge_style(status): qproperty-alignment: AlignCenter; background-color: {colors["background"]}; color: {colors["color"]}; - font-size: 14px; border-radius: 5px; font-family: 'Poppins'; font-weight: bold; @@ -511,7 +509,6 @@ STEAM_BADGE_STYLE= """ qproperty-alignment: AlignCenter; background: rgba(0, 0, 0, 0.5); color: white; - font-size: 14px; border-radius: 5px; font-family: 'Poppins'; font-weight: bold; diff --git a/portprotonqt/themes/standart/styles.py b/portprotonqt/themes/standart/styles.py index f51218c..a36fbfa 100644 --- a/portprotonqt/themes/standart/styles.py +++ b/portprotonqt/themes/standart/styles.py @@ -641,7 +641,6 @@ def get_protondb_badge_style(tier): qproperty-alignment: AlignCenter; background-color: {colors["background"]}; color: {colors["color"]}; - font-size: {font_size_a}; border-radius: 5px; font-family: '{font_family}'; font-weight: bold; @@ -664,7 +663,6 @@ def get_anticheat_badge_style(status): color: {colors["color"]}; font-size: {font_size_a}; border-radius: 5px; - font-family: '{font_family}'; font-weight: bold; """ @@ -673,7 +671,6 @@ STEAM_BADGE_STYLE= f""" qproperty-alignment: AlignCenter; background: rgba(0, 0, 0, 0.5); color: white; - font-size: {font_size_a}; border-radius: 5px; font-family: '{font_family}'; font-weight: bold;