summaryrefslogtreecommitdiffstats
path: root/src/widgets/styles/qcommonstyle.cpp
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2018-04-24 20:31:13 +0200
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2018-04-26 16:37:21 +0000
commitb2a282d7c7b8f49819bbc86ed705980438ecb04b (patch)
treed0da997a696f8d15f3b646c409500b63eb7b7aa6 /src/widgets/styles/qcommonstyle.cpp
parentfcc94b1442ce910231a4267bd56822d616984683 (diff)
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 <gabriel.dedietrich@qt.io>
Diffstat (limited to 'src/widgets/styles/qcommonstyle.cpp')
-rw-r--r--src/widgets/styles/qcommonstyle.cpp3
1 files changed, 2 insertions, 1 deletions
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);