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>
bb10
Christian Ehrlicher 2018-04-24 20:31:13 +02:00
parent fcc94b1442
commit b2a282d7c7
1 changed files with 2 additions and 1 deletions

View File

@ -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);