summaryrefslogtreecommitdiffstats
path: root/src/widgets/styles
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2019-01-27 21:15:52 +0100
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2019-02-07 05:32:37 +0000
commit7024090e1dc7043e7a2a692ede105bcb7952781d (patch)
treef67335829b56103698acc7126d8e609c45a7d58b /src/widgets/styles
parenta7ba79553c364df9ab55c5c177b15606191cd568 (diff)
QToolButton: fix handling multi-line texts
The patch to elide the QToolButton text when there is not enough space introduced a regression with multi-line text. Fix it by using the newly introduced common function to elide multi-line text. Fixes: QTBUG-72226 Change-Id: I066ebbd2f360add93406cc29bb4bbbebf599ba42 Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/widgets/styles')
-rw-r--r--src/widgets/styles/qcommonstyle.cpp22
-rw-r--r--src/widgets/styles/qcommonstyle_p.h5
2 files changed, 25 insertions, 2 deletions
diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp
index 867e91ab3e..79e338a6e7 100644
--- a/src/widgets/styles/qcommonstyle.cpp
+++ b/src/widgets/styles/qcommonstyle.cpp
@@ -1157,6 +1157,25 @@ void QCommonStylePrivate::viewItemLayout(const QStyleOptionViewItem *opt, QRect
}
#endif // QT_CONFIG(itemviews)
+#if QT_CONFIG(toolbutton)
+QString QCommonStylePrivate::toolButtonElideText(const QStyleOptionToolButton *option,
+ const QRect &textRect, int flags) const
+{
+ if (option->fontMetrics.horizontalAdvance(option->text) <= textRect.width())
+ return option->text;
+
+ QString text = option->text;
+ text.replace('\n', QChar::LineSeparator);
+ QTextOption textOption;
+ textOption.setWrapMode(QTextOption::ManualWrap);
+ textOption.setTextDirection(option->direction);
+
+ return calculateElidedText(text, textOption,
+ option->font, textRect, Qt::AlignTop,
+ Qt::ElideMiddle, flags,
+ false, nullptr);
+}
+#endif // QT_CONFIG(toolbutton)
#if QT_CONFIG(tabbar)
/*! \internal
@@ -1705,8 +1724,7 @@ 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(), alignment);
+ const QString text = d->toolButtonElideText(toolbutton, tr, alignment);
proxy()->drawItemText(p, QStyle::visualRect(opt->direction, rect, tr), alignment, toolbutton->palette,
toolbutton->state & State_Enabled, text,
QPalette::ButtonText);
diff --git a/src/widgets/styles/qcommonstyle_p.h b/src/widgets/styles/qcommonstyle_p.h
index f0131b7a58..296f89ce5f 100644
--- a/src/widgets/styles/qcommonstyle_p.h
+++ b/src/widgets/styles/qcommonstyle_p.h
@@ -115,6 +115,11 @@ public:
&& option.viewItemPosition == cachedOption->viewItemPosition);
}
#endif
+#if QT_CONFIG(toolbutton)
+ QString toolButtonElideText(const QStyleOptionToolButton *toolbutton,
+ const QRect &textRect, int flags) const;
+#endif
+
mutable QIcon tabBarcloseButtonIcon;
#if QT_CONFIG(tabbar)
void tabLayout(const QStyleOptionTab *opt, const QWidget *widget, QRect *textRect, QRect *pixmapRect) const;