Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Tabs not working as intended for monospace font on Linux
Forum Updated to NodeBB v4.3 + New Features

Tabs not working as intended for monospace font on Linux

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Robbinb1993
    wrote on last edited by Robbinb1993
    #1

    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?

    alt text

    alt text

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Robbinb1993
      wrote on last edited by
      #2

      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?

      jsulmJ 1 Reply Last reply
      0
      • R Robbinb1993

        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?

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @Robbinb1993 You should check https://bugreports.qt.io/secure/Dashboard.jspa and file a bug if there is nothing.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        aha_1980A 1 Reply Last reply
        1
        • jsulmJ jsulm

          @Robbinb1993 You should check https://bugreports.qt.io/secure/Dashboard.jspa and file a bug if there is nothing.

          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @jsulm

          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);
          

          Qt has to stay free or it will die.

          R 1 Reply Last reply
          3
          • aha_1980A aha_1980

            @jsulm

            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);
            
            R Offline
            R Offline
            Robbinb1993
            wrote on last edited by
            #5

            @aha_1980
            Thank you! font.setStyleStrategy(QFont::ForceIntegerMetrics); fixed the problem, found in the comment section of the bug report.

            aha_1980A 1 Reply Last reply
            2
            • R Robbinb1993

              @aha_1980
              Thank you! font.setStyleStrategy(QFont::ForceIntegerMetrics); fixed the problem, found in the comment section of the bug report.

              aha_1980A Offline
              aha_1980A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Robbinb1993

              Cool! Glad I could help, and thanks for sharing!

              Qt has to stay free or it will die.

              1 Reply Last reply
              2

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved