[LyX/master] Fix Qt deprecation warns for setting tab
Scott Kostyshak
skostysh at lyx.org
Sun Mar 8 15:30:22 UTC 2020
commit 2cfcd706ab92f0e4175f40ed931293802cd5a623
Author: Scott Kostyshak <skostysh at lyx.org>
Date: Sun Mar 8 11:16:28 2020 -0400
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
---
src/frontends/qt/GuiDocument.cpp | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/src/frontends/qt/GuiDocument.cpp b/src/frontends/qt/GuiDocument.cpp
index 2d1cc76..9ae6840 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
}
More information about the lyx-cvs
mailing list