QTextEdit 、QPlainTextEdit设置插入字体颜色

来源:互联网 发布:excel数据分析在哪里 编辑:程序博客网 时间:2024/05/21 17:09

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;
}

原创粉丝点击