QTextEdit 、QPlainTextEdit设置插入字体颜色

    技术2025-06-21  12

    QTextEdit 和QPlainTextEdit本身没有提供设置插入字体的颜色的API,可以自定义一个setInsertTextColor(const QColor & c)来实现:

    void XXXX::setInsertTextColor(QColor col,BackOrFore wground){             QTextCharFormat fmt;             fmt.setForeground(col);             QTextCursor cursor = textCursor();             cursor.mergeCharFormat(fmt);             mergeCurrentCharFormat(fmt);调用QTextEdit或者QPlianTextEdit的api;}

    最新回复(0)