Tabs not working as intended for monospace font on Linux
-
I have created a QPlainTextEdit that uses the Courier font. However when I use tabs in Linux, the tab distance is not correct and character positions get out of sync. I tried to manually set it with the setTabStopDistance function to 3 times the width of the space character, but this still did not fix the problem. I also have tried other fonts, like the Monospace Regular font on Ubuntu, but the problem remains. How do I fix this?
-
Additional info:
I am running Qt 5.10.0 on Ubuntu 16.04 LTS. QTextEdit also has the same problem.
I found a topic where someone posted a similar problem (a long time ago): http://lists.qt-project.org/pipermail/qt-interest-old/2009-June/007894.html . Does anyone have a clue? -
Additional info:
I am running Qt 5.10.0 on Ubuntu 16.04 LTS. QTextEdit also has the same problem.
I found a topic where someone posted a similar problem (a long time ago): http://lists.qt-project.org/pipermail/qt-interest-old/2009-June/007894.html . Does anyone have a clue?@Robbinb1993 You should check https://bugreports.qt.io/secure/Dashboard.jspa and file a bug if there is nothing.
-
@Robbinb1993 You should check https://bugreports.qt.io/secure/Dashboard.jspa and file a bug if there is nothing.
I've searched the bug database and the only result I found is QTCREATORBUG-833.
@Robbinb1993: Does this bug look similar to your problem?
The fix for that bug looks like this, btw.:
// Although the tab stop is stored as qreal the API from QPlainTextEdit only allows // it to be set as an int. A work around is to access directly the QTextOption. qreal charWidth = QFontMetricsF(font()).width(QChar(' ')); QTextOption option = document()->defaultTextOption(); option.setTabStop(charWidth * ts.m_tabSize); document()->setDefaultTextOption(option);
-
I've searched the bug database and the only result I found is QTCREATORBUG-833.
@Robbinb1993: Does this bug look similar to your problem?
The fix for that bug looks like this, btw.:
// Although the tab stop is stored as qreal the API from QPlainTextEdit only allows // it to be set as an int. A work around is to access directly the QTextOption. qreal charWidth = QFontMetricsF(font()).width(QChar(' ')); QTextOption option = document()->defaultTextOption(); option.setTabStop(charWidth * ts.m_tabSize); document()->setDefaultTextOption(option);
@aha_1980
Thank you! font.setStyleStrategy(QFont::ForceIntegerMetrics); fixed the problem, found in the comment section of the bug report. -
@aha_1980
Thank you! font.setStyleStrategy(QFont::ForceIntegerMetrics); fixed the problem, found in the comment section of the bug report.Cool! Glad I could help, and thanks for sharing!