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>
This commit is contained in:
parent
a7ba79553c
commit
7024090e1d
@ -1157,6 +1157,25 @@ void QCommonStylePrivate::viewItemLayout(const QStyleOptionViewItem *opt, QRect
|
|||||||
}
|
}
|
||||||
#endif // QT_CONFIG(itemviews)
|
#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)
|
#if QT_CONFIG(tabbar)
|
||||||
/*! \internal
|
/*! \internal
|
||||||
@ -1705,8 +1724,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
|
|||||||
alignment |= Qt::AlignLeft | Qt::AlignVCenter;
|
alignment |= Qt::AlignLeft | Qt::AlignVCenter;
|
||||||
}
|
}
|
||||||
tr.translate(shiftX, shiftY);
|
tr.translate(shiftX, shiftY);
|
||||||
const QString text = toolbutton->fontMetrics.elidedText(toolbutton->text, Qt::ElideMiddle,
|
const QString text = d->toolButtonElideText(toolbutton, tr, alignment);
|
||||||
tr.width(), alignment);
|
|
||||||
proxy()->drawItemText(p, QStyle::visualRect(opt->direction, rect, tr), alignment, toolbutton->palette,
|
proxy()->drawItemText(p, QStyle::visualRect(opt->direction, rect, tr), alignment, toolbutton->palette,
|
||||||
toolbutton->state & State_Enabled, text,
|
toolbutton->state & State_Enabled, text,
|
||||||
QPalette::ButtonText);
|
QPalette::ButtonText);
|
||||||
|
@ -115,6 +115,11 @@ public:
|
|||||||
&& option.viewItemPosition == cachedOption->viewItemPosition);
|
&& option.viewItemPosition == cachedOption->viewItemPosition);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#if QT_CONFIG(toolbutton)
|
||||||
|
QString toolButtonElideText(const QStyleOptionToolButton *toolbutton,
|
||||||
|
const QRect &textRect, int flags) const;
|
||||||
|
#endif
|
||||||
|
|
||||||
mutable QIcon tabBarcloseButtonIcon;
|
mutable QIcon tabBarcloseButtonIcon;
|
||||||
#if QT_CONFIG(tabbar)
|
#if QT_CONFIG(tabbar)
|
||||||
void tabLayout(const QStyleOptionTab *opt, const QWidget *widget, QRect *textRect, QRect *pixmapRect) const;
|
void tabLayout(const QStyleOptionTab *opt, const QWidget *widget, QRect *textRect, QRect *pixmapRect) const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user