Skip to content

Commit 83de98f

Browse files
committed
ui: use dynamic bottom padding for capsule font
1 parent 86f5881 commit 83de98f

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

‎src/tagstudio/qt/views/styles/stylesheets.py‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
# SPDX-License-Identifier: GPL-3.0-only
33

44

5+
import math
56
import platform
67

78
from PySide6.QtCore import QSize, Qt
8-
from PySide6.QtGui import QColor, QGuiApplication
9+
from PySide6.QtGui import QColor, QFont, QFontMetricsF, QGuiApplication
910

1011
from tagstudio.core.library.alchemy.enums import TagColorEnum
1112
from tagstudio.core.library.alchemy.models import TagColorGroup
@@ -38,6 +39,8 @@
3839
CHECKBOX_SIZE = 20 # Checkboxes and radio buttons
3940
FLAT_ICON_SIZE = 24 # Icons on flat icon-only buttons, like the mode rail's
4041
CAPSULE_HEIGHT = 24
42+
CAPSULE_FONT_SIZE = 13
43+
CAPSULE_FONT_WEIGHT = QFont.Weight.DemiBold
4144
SWATCH_SIZE = 24
4245
CHEVRON_SIZE = QSize(20, 20)
4346

@@ -108,17 +111,23 @@ def capsule_text_style(
108111
) -> str:
109112
"""Style used for Capsule text."""
110113
side_padding = 4 + (3 if is_pill else 0)
114+
# Set the font baseline depending on the metrics instead of a constant value
115+
font = QFont()
116+
font.setPixelSize(CAPSULE_FONT_SIZE)
117+
font.setWeight(CAPSULE_FONT_WEIGHT)
118+
metrics = QFontMetricsF(font)
119+
bottom_padding = math.floor(metrics.ascent() - metrics.descent() - metrics.capHeight())
111120
return f"""
112121
QPushButton{{
113122
background: transparent;
114123
color: rgba{text_color.toTuple()};
115-
font-weight: 600;
124+
font-weight: {CAPSULE_FONT_WEIGHT.value};
116125
border: 2px solid transparent;
117126
border-radius: {RADIUS}px;
118-
font-size: 13px;
127+
font-size: {CAPSULE_FONT_SIZE}px;
119128
padding-right: {side_padding if right_padding is None else right_padding}px;
120129
padding-left: {side_padding if left_padding is None else left_padding}px;
121-
padding-bottom: {2 if platform.system() == "Windows" else 1}px;
130+
padding-bottom: {bottom_padding}px;
122131
}}
123132
QPushButton::pressed{{
124133
color: rgba{pressed_text_color.toTuple()};

0 commit comments

Comments
 (0)