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. QTextEdit with a monospaced font - delete char (127) has unusual width

QTextEdit with a monospaced font - delete char (127) has unusual width

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 3.1k 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.
  • F Offline
    F Offline
    frankiefrank
    wrote on 24 Nov 2014, 16:57 last edited by
    #1

    OK, this may be very specific so apologies in advance.

    I'm using QTextEdit to display data and to make it monospaced I'm using "Courier New" as a font family.

    All is well except that I wanted to display some symbol to represent an unavailable character. I chose the delete character (ascii 127) which shows a small empty box, but it appears that the width of the character is actually different from the other (printable) characters. Using point size 10, I ran a small loop with QFontMetrics and it appears that the delete character width is 7 while all other chars are 8.

    Shouldn't the monospaced font by definition have the same width for each character?

    "Roads? Where we're going, we don't need roads."

    1 Reply Last reply
    0
    • F Offline
      F Offline
      frankiefrank
      wrote on 24 Feb 2015, 12:54 last edited by
      #2

      Any ideas, Qt community?

      "Roads? Where we're going, we don't need roads."

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Rondog
        wrote on 24 Feb 2015, 13:44 last edited by
        #3

        I ran some tests and didn't see this. I have two examples:

        courier new point size 10:
        https://www.dropbox.com/s/ubv8ymzilriscde/courier_new-10.png?dl=0

        courier new point size 20:
        https://www.dropbox.com/s/6b6131ok2ndnexk/courier_new-20.png?dl=0

        I used character ascii(1) instead of ascii(127). Ascii(127) is a delete character so is it possible that your text is reduced in size for every one of these used?

        1 Reply Last reply
        0
        • F Offline
          F Offline
          frankiefrank
          wrote on 24 Feb 2015, 13:49 last edited by
          #4

          Thanks for checking Rondog, Could you maybe get short links for the Dropbox urls? They don't seem to work for me, even when I copy paste the entire link into the address bar.

          "Roads? Where we're going, we don't need roads."

          1 Reply Last reply
          0
          • R Offline
            R Offline
            Rondog
            wrote on 24 Feb 2015, 14:04 last edited by
            #5

            I updated the links in the post. Originally they had spaces in the name. Your idea would have worked except I deleted the original, spaced, names.

            1 Reply Last reply
            0
            • R Offline
              R Offline
              Rondog
              wrote on 24 Feb 2015, 16:14 last edited by
              #6

              One thing I would like to add that seems to be an obvious omission.

              I tried to run this test using ascii(127) but nothing appeared in QTextEdit (or QPlainTextEdit) for this character. I added some padding text to be sure then switched to ascii(1).

              It is possible there is something different about '127' but I couldn't test this. I didn't check it with QFontMetrics. There are a number of attributes in fonts that might be used to determine the cell width for a character. Maybe anything that displays a box symbol has a combined width of various attributes that is identical for all characters?

              1 Reply Last reply
              0
              • T Offline
                T Offline
                T3STY
                wrote on 27 Feb 2015, 02:13 last edited by
                #7

                not really something different, but something missing. It might be that Courier New is missing the character 127, so QFont will search for it in another font. Build a well defined QFont with family name, font name with fixed pitch:

                @
                QFont myFont;
                // font-family [Font name]
                myFont.setFamily("monospace [Courier New]");
                // Tell QFont that the font you're using IS monospaced - QFont will try to render it as monospaced
                myFont.setFixedPitch(true);
                // ask QFont to use a monospaced font when the specified font (in family) is not available
                myFont.setStyleHint(QFont::Monospace);
                @
                Now, every time the specified font is not available, or a character is unot available in the specified font name, QFont will search for it in another monospaced font. However, QFont will not ensure that the character imported from another font is the same size as the others from the specified font. At most, you can use QFont::maxWidth() to find out the width of the widest character available (no character will ever be larger than that).

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  Rondog
                  wrote on 27 Feb 2015, 03:24 last edited by
                  #8

                  I don't think it works that way. Font substituion is not for individual characters.

                  There is no glyph for ascii(127) so displaying a box is suitable. I assume the same happens for all non-assigned characters from any font (I don't know the rules for this sort of thing).

                  The cell width for a fixed spaced font must always be the same otherwise it is not a fixed spaced font.

                  1 Reply Last reply
                  0

                  • Login

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