From: Scott Kostyshak Date: Sun, 8 Mar 2020 15:16:28 +0000 (-0400) Subject: Fix Qt deprecation warns for setting tab X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=752ec9185c9c53139b9704826222718104aea872;p=features.git Fix Qt deprecation warns for setting tab 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 --- diff --git a/src/frontends/qt/GuiDocument.cpp b/src/frontends/qt/GuiDocument.cpp index 2d1cc7628f..9ae68405f7 100644 --- a/src/frontends/qt/GuiDocument.cpp +++ b/src/frontends/qt/GuiDocument.cpp @@ -495,7 +495,13 @@ PreambleModule::PreambleModule(QWidget * parent) // 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 }