From 40d708f9c5614d37e638c2dd2e4ae67cd7b53f66 Mon Sep 17 00:00:00 2001 From: Ismael Asensio Date: Mon, 7 Jun 2021 19:35:18 +0200 Subject: [PATCH] kcm/kwinrules: Adapt spinbox width to actual text Use FontMetrics to calculate the expected max text width so it doesn't overflow with wider fonts, specially in some languages like pt_BR BUG: 438193 FIXED-IN: 5.22.1 --- .../kwinrules/package/contents/ui/RulesEditor.qml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/kcmkwin/kwinrules/package/contents/ui/RulesEditor.qml b/src/kcmkwin/kwinrules/package/contents/ui/RulesEditor.qml index c10d592f36..4044a1e177 100644 --- a/src/kcmkwin/kwinrules/package/contents/ui/RulesEditor.qml +++ b/src/kcmkwin/kwinrules/package/contents/ui/RulesEditor.qml @@ -107,13 +107,24 @@ ScrollViewKCM { QQC2.SpinBox { id: delaySpin enabled: detectButton.enabled - Layout.preferredWidth: Kirigami.Units.gridUnit * 8 + Layout.preferredWidth: Math.max(metricsInstant.advanceWidth, metricsAfter.advanceWidth) + Kirigami.Units.gridUnit * 2 from: 0 to: 30 textFromValue: (value, locale) => { return (value == 0) ? i18n("Instantly") : i18np("After %1 second", "After %1 seconds", value) } + + TextMetrics { + id: metricsInstant + font: delaySpin.font + text: i18n("Instantly") + } + TextMetrics { + id: metricsAfter + font: delaySpin.font + text: i18np("After %1 second", "After %1 seconds", 99) + } } }