[SOVLED] How to use monospaced fonts with QTextEdit?

  • 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]");
    textWidget = new QTextEdit;
    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?

  • 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.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.