[plasma/union/Plasma/6.7] src/output/qtquick/style: output/quick: Limit maximum width of text in tooltips to 70 characters
Arjen Hiemstra <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit fbb5424e09b9a4607bf42b4bc1147f4a9deac600 by Arjen Hiemstra. Committed on 17/07/2026 at 14:25. Pushed by ahiemstra into branch 'Plasma/6.7'. output/quick: Limit maximum width of text in tooltips to 70 characters 70 characters is considered to be a "good" maximum line length, so make sure we limit things to that. BUG: 521855 (cherry picked from commit 95f0208f567234ad768a962abd0741c0b4778357) Co-authored-by: Arjen Hiemstra <[email protected]> M +12 -1 src/output/qtquick/style/ToolTip.qml https://invent.kde.org/plasma/union/-/commit/fbb5424e09b9a4607bf42b4bc1147f4a9deac600 diff --git a/src/output/qtquick/style/ToolTip.qml b/src/output/qtquick/style/ToolTip.qml index 401af948..8d1eca6f 100644 --- a/src/output/qtquick/style/ToolTip.qml +++ b/src/output/qtquick/style/ToolTip.qml @@ -22,7 +22,7 @@ T.ToolTip { y: -implicitHeight implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, - implicitContentWidth + leftPadding + rightPadding) + Math.min(implicitContentWidth, contentItem.maximumWidth) + leftPadding + rightPadding) implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, implicitContentHeight + topPadding + bottomPadding) @@ -55,12 +55,23 @@ T.ToolTip { popupType: T.Popup.Item contentItem: Text { + // A maximum width for the contents of the tooltip. This is calculated to + // fit 70 characters which is usually considered a good line length. + // + // TODO: Add max-width and em support so this can be expressed in CSS. + readonly property real maximumWidth: metrics.averageCharacterWidth * 70 + text: control.text font: control.font wrapMode: Text.Wrap color: Union.Style.properties.text.color ?? control.palette.text horizontalAlignment: Union.Alignment.toQtHorizontal(Union.Style.properties.text.alignment.horizontal) verticalAlignment: Union.Alignment.toQtVertical(Union.Style.properties.text.alignment.vertical) + + FontMetrics { + id: metrics + font: control.font + } } background: Union.StyledRectangle {}