From b2a282d7c7b8f49819bbc86ed705980438ecb04b Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Tue, 24 Apr 2018 20:31:13 +0200 Subject: [PATCH] QToolButton: Elide text when constraints prevent from showing whole text When a QToolButton has a fixed width and the text is too long, the text was cropped which made the button look ugly. Fix it by eliding the text in the middle in this case. Task-number: QTBUG-64132 Change-Id: I7bc46d1edcf4e67b5e1a5b651d4793f9ffa15310 Reviewed-by: Gabriel de Dietrich --- src/widgets/styles/qcommonstyle.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index c2f96ba68b..ce76748347 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -1667,8 +1667,9 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt, alignment |= Qt::AlignLeft | Qt::AlignVCenter; } tr.translate(shiftX, shiftY); + const QString text = toolbutton->fontMetrics.elidedText(toolbutton->text, Qt::ElideMiddle, tr.width()); proxy()->drawItemText(p, QStyle::visualRect(opt->direction, rect, tr), alignment, toolbutton->palette, - toolbutton->state & State_Enabled, toolbutton->text, + toolbutton->state & State_Enabled, text, QPalette::ButtonText); } else { rect.translate(shiftX, shiftY);