Fix error: 'width' is deprecated: Use QFontMetrics::horizontalAdvance.

This commit is contained in:
Roman Telezhynskyi 2020-10-28 17:22:47 +02:00
parent 0b7479ce98
commit 9e3e59d267
2 changed files with 8 additions and 0 deletions

View File

@ -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);

View File

@ -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);