mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-26 07:26:15 +01:00
qt: Add TextWidth() wrapper
In Qt 5.12 and before the QFontMetrics::width() is used and it is deprecated since Qt 13.0. In Qt 5.11 the QFontMetrics::horizontalAdvance() was introduced.
This commit is contained in:
@@ -916,7 +916,7 @@ qreal calculateIdealFontSize(int width, const QString& text, QFont font, qreal m
|
||||
while(font_size >= minPointSize) {
|
||||
font.setPointSizeF(font_size);
|
||||
QFontMetrics fm(font);
|
||||
if (fm.width(text) < width) {
|
||||
if (TextWidth(fm, text) < width) {
|
||||
break;
|
||||
}
|
||||
font_size -= 0.5;
|
||||
@@ -956,4 +956,13 @@ void PolishProgressDialog(QProgressDialog* dialog)
|
||||
#endif
|
||||
}
|
||||
|
||||
int TextWidth(const QFontMetrics& fm, const QString& text)
|
||||
{
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
|
||||
return fm.horizontalAdvance(text);
|
||||
#else
|
||||
return fm.width(text);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace GUIUtil
|
||||
|
||||
Reference in New Issue
Block a user