@@ -53,8 +53,6 @@ CodeEditor::CodeEditor(QWidget* parent, const std::string& filename)
5353 setLineWrapMode (QPlainTextEdit::NoWrap);
5454 document ()->setDefaultFont (fixedFont ());
5555
56- setTabStopDistance (4 * char_width_pixels ());
57-
5856 lineNumberArea = new LineNumberArea (this );
5957
6058 connect (this , SIGNAL (blockCountChanged (int )), this ,
@@ -66,6 +64,7 @@ CodeEditor::CodeEditor(QWidget* parent, const std::string& filename)
6664
6765 updateLineNumberAreaWidth (0 );
6866 highlightCurrentLine ();
67+ setTabStopDistance (4 * char_width_pixels ());
6968}
7069
7170
@@ -100,11 +99,12 @@ CodeEditor::text_string() const
10099int
101100CodeEditor::char_width_pixels () const
102101{
103- #if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
104- return fontMetrics ().horizontalAdvance (QLatin1Char (' M' ));
102+ QFontMetrics metrics (fixedFont ());
103+ #if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
104+ return metrics.horizontalAdvance (QLatin1Char (' M' ));
105105#else
106106 // QFontMetric.width() deprecated from 5.11, marked as such in 5.13
107- return fontMetrics () .width (QLatin1Char (' M' ));
107+ return metrics .width (QLatin1Char (' M' ));
108108#endif
109109}
110110
0 commit comments