[SOLVED] How to fix the font of qtextedit.



  • Hello all!

    I'm writing a texteditor in qt (4.8.5) mainly for learning. The problem I'm facing is that qtextedit changes it's font once all of the text is deleted. Is there a way for me to disable that feature and set a document wide font? I want to have monospace font in order to calculate the cursor position (line/char). I set the font by

    @
    QTextEdit *editor = new QTextEdit();
    editor->acceptRichText(false);
    editor->setCurrentFont(QFont("Monospace", 10));
    @

    The reason I'm using qtextedit instead of qplaintext is for syntax highlighting and text completion (which I haven't implemented yet).

    SOLUTION:
    @
    QTextEdit *editor = new QTextEdit();
    ((QWidget *)editor)->setFont(QFont("Monospace", 10));
    @


  • Lifetime Qt Champion

    Hi,

    You should use setFont, setCurrentFont is used to change the font "starting now" in your document.


Log in to reply
 

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