Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QTextEdit Text Option use Error.



  • I modified QTextEdit to change the size, font, and color of the text.

    After creating the contents, change the attributes (size, font, color) and press the return key (Ctrl + Z), the previous attributes are not maintained and the 20th color is returned to black again.

    Is there a way to keep it?

    QTextCharFormat newFormat;
    newFormat.setFont(font);
    newFormat.setFontPointSize(fontSize);
    newFormat.setFontWeight(isBold ? QFont::Bold : QFont::Normal);
    newFormat.setFontUnderline(isUnderLine);
    newFormat.setFontItalic(isitalic);
    newFormat.setForeground(color);

    textEdit->setFont(font);
    textEdit->setCurrentCharFormat(newFormat);
    

    Then, when you write the text again, the first character will return to font size and color 20. However, from the second letter, it will be displayed in the size and color set above.

    How do I make changes to the first one?


  • Lifetime Qt Champion

    Hi,

    What version of Qt are you using ?
    On what platform ?



  • @SGaist

    Windows 8 64Bit
    Windows 10 64Bit
    Linux

    Qt 5.4

    The platform does not seem to matter. It seems to be because there is no code that can put the old one back when you run undo.


  • Lifetime Qt Champion

    Qt 5.4 being pretty outdated, did you check whether you still have the same behaviour with 5.12 or the current 5.13 preview ?


Log in to reply