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;
}
本文介绍如何为QTextEdit和QPlainTextEdit组件自定义插入文本的颜色。通过实现setInsertTextColor方法,可以方便地更改输入文字的颜色。
1276

被折叠的 条评论
为什么被折叠?



