From 9e3e59d26702a78eba8a1e73a781c53eac4c3e58 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 28 Oct 2020 17:22:47 +0200 Subject: [PATCH] Fix error: 'width' is deprecated: Use QFontMetrics::horizontalAdvance. --- src/libs/vpropertyexplorer/plugins/vtextproperty.cpp | 4 ++++ src/libs/vtools/dialogs/dialogtoolbox.cpp | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/libs/vpropertyexplorer/plugins/vtextproperty.cpp b/src/libs/vpropertyexplorer/plugins/vtextproperty.cpp index 0e9ae1d1d..69d1a9781 100644 --- a/src/libs/vpropertyexplorer/plugins/vtextproperty.cpp +++ b/src/libs/vpropertyexplorer/plugins/vtextproperty.cpp @@ -39,7 +39,11 @@ void SetTabStopDistance(QPlainTextEdit *edit, int tabWidthChar) #else // compute the size of a char in double-precision static constexpr int bigNumber = 1000; // arbitrary big number. +#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) + const int many_char_width = fontMetrics.horizontalAdvance(testString.repeated(bigNumber)); +#else const int many_char_width = fontMetrics.width(testString.repeated(bigNumber)); +#endif const double singleCharWidthDouble = many_char_width / double(bigNumber); // set the tab stop with double precision edit->setTabStopDistance(tabWidthChar * singleCharWidthDouble); diff --git a/src/libs/vtools/dialogs/dialogtoolbox.cpp b/src/libs/vtools/dialogs/dialogtoolbox.cpp index ef757a014..45b950c2e 100644 --- a/src/libs/vtools/dialogs/dialogtoolbox.cpp +++ b/src/libs/vtools/dialogs/dialogtoolbox.cpp @@ -501,7 +501,11 @@ void SetTabStopDistance(QPlainTextEdit *edit, int tabWidthChar) #else // compute the size of a char in double-precision static constexpr int bigNumber = 1000; // arbitrary big number. +#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) + const int many_char_width = fontMetrics.horizontalAdvance(testString.repeated(bigNumber)); +#else const int many_char_width = fontMetrics.width(testString.repeated(bigNumber)); +#endif const double singleCharWidthDouble = many_char_width / double(bigNumber); // set the tab stop with double precision edit->setTabStopDistance(tabWidthChar * singleCharWidthDouble);