fix: elide overflowed badge text in ClickableLabel
Signed-off-by: Boris Yumankulov <boria138@altlinux.org>
This commit is contained in:
@ -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(),
|
||||
)
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user