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.
Thanks.
Edit:
Including the images to exemplify...
From this:
To this:
Thanks.
Edit2: Final Look
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With