]> git.lyx.org Git - features.git/commitdiff
Fix Qt deprecation warns for setting tab
authorScott Kostyshak <skostysh@lyx.org>
Sun, 8 Mar 2020 15:16:28 +0000 (11:16 -0400)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2020 13:48:53 +0000 (15:48 +0200)
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

src/frontends/qt/GuiDocument.cpp

index 2d1cc7628fac821172028feeebfec09bd2758218..9ae68405f7e5ef4fac3e0fdbdabbfef64c23a2d3 100644 (file)
@@ -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
 }