Qt 5.3 QPlainTextEdit 更改 QTextCursor 颜色 [英] Qt 5.3 QPlainTextEdit Change the QTextCursor color
本文介绍了Qt 5.3 QPlainTextEdit 更改 QTextCursor 颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想更改 QPlainTextEdit
小部件下的光标颜色.我能够将其宽度设置为 6
,但我想更改颜色或它.可能吗?
I would like to change the cursor color under the QPlainTextEdit
widget. I was able to set it's width to 6
, but I want to change the color or it. Is it possible ?
QFontMetrics fm(font());
setCursorWidth( fm.averageCharWidth() );
//setCursorColor is what I need.
谢谢.
包括图像来举例说明...
Including the images to exemplify...
从这里:
为此:
谢谢.
Edit2:最终外观
推荐答案
您可以使用 QTextCharFormat
来设置 QPlainTextEdit
中文本的颜色.使用 QTextCharFormat::setForeground
设置颜色.然后使用样式表通过 color
属性更改光标的颜色.
You can use QTextCharFormat
to set the color of the text in your QPlainTextEdit
. Use the QTextCharFormat::setForeground
to set the color.
Then use a stylesheet to change the color of the cursor by using the color
property.
QPlainTextEdit *p_textEdit = new QPlainTextEdit;
p_textEdit->setStyleSheet("QPlainTextEdit{color: #ffff00; background-color: #303030;"
" selection-background-color: #606060; selection-color: #ffffff;}");
QTextCharFormat fmt;
fmt.setForeground(QBrush(QColor(255,255,255)));
p_textEdit->mergeCurrentCharFormat(fmt);
这篇关于Qt 5.3 QPlainTextEdit 更改 QTextCursor 颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文