aboutsummaryrefslogtreecommitdiff
path: root/src/qt/guiutil.cpp
diff options
context:
space:
mode:
authorHennadii Stepanov <32963518+hebasto@users.noreply.github.com>2019-08-23 20:13:11 +0300
committerHennadii Stepanov <32963518+hebasto@users.noreply.github.com>2019-08-23 21:27:50 +0300
commit1260ecd812e35185898fd555ad3e01d019072bcf (patch)
tree02a9912efdfadafbea77535b6730b141167a569f /src/qt/guiutil.cpp
parent442a9c64775454a7073aff9872721c58b1dd35c5 (diff)
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.
Diffstat (limited to 'src/qt/guiutil.cpp')
-rw-r--r--src/qt/guiutil.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp
index dc1da7f8a9..5c5901e076 100644
--- a/src/qt/guiutil.cpp
+++ b/src/qt/guiutil.cpp
@@ -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