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. [SOVLED] How to use monospaced fonts with QTextEdit?
Forum Updated to NodeBB v4.3 + New Features

[SOVLED] How to use monospaced fonts with QTextEdit?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 3.6k Views 1 Watching
  • 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.
  • T3STYT Offline
    T3STYT Offline
    T3STY
    wrote on last edited by
    #1

    I have a QTextEdit and I want to use a monospaced font. Although, any attempts to use one failed. At most it changed a bit the spacing between characters, but nothing more, and in no way it used a monospaced font.
    My code is placed inside an object's contructor, and works like this:
    @
    ...
    textFont = new QFont;
    textFont->setFamily("monospace [Consolas]");
    textFont->setFixedPitch(true);
    textFont->setStyleHint(QFont::TypeWriter);
    ...
    textWidget = new QTextEdit;
    textWidget->setCurrentFont(*textFont);
    @
    Whatever settings I try to use they don't give me the desired effect. Also, did I miss it or there is no method in QFont that simply allows to set a font's name? I read in some replies on other forums about a QFont.setFont("font name") method, but it's not available in Qt 5.3 and 5.4.

    Any help, please?

    1 Reply Last reply
    0
    • T3STYT Offline
      T3STYT Offline
      T3STY
      wrote on last edited by
      #2

      I found the solution... I was mistakenly using QTextEdit::setCurrentFont() instead of QTextEdit::setFont(). The last one acts globally, while the first one only acts on new input from keyboard.

      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