Fix warnings coming from deprecations of QTextEdit::tabStopWidth()
and QFontMetrics::width(). Regarding tabStopWidth(), the ChangeLog
states the following [1]:
Introduced tabStopDistance property in QTextOption, QTextEdit and
QPlainTextEdit as replacement for the inconsistently named tabStop and
tabStopWidth properties. QTextOption::tabStop, QTextEdit::tabStopWidth and
QPlainTextEdit::tabStopWidth are now deprecated.
Note that QFontMetrics::horizontalAdvance() is what we want here, as
opposed to QFontMetrics::boundingRect(), because we want to know
where to draw the next character after the tab.
[1] https://code.qt.io/cgit/qt/qtbase.git/tree/dist/changes-5.10.0/?h=v5.10.0
// https://stackoverflow.com/questions/13027091/how-to-override-tab-width-in-qt
const int tabStop = 4;
QFontMetrics metrics(preambleTE->currentFont());
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
+ // horizontalAdvance() is available starting in 5.11.0
+ // setTabStopDistance() is available starting in 5.10.0
+ preambleTE->setTabStopDistance(tabStop * metrics.horizontalAdvance(' '));
+#else
preambleTE->setTabStopWidth(tabStop * metrics.width(' '));
+#endif
}