How to set QPlainTextEdit text background color?
-
I've tried
setStyleSheet
with"background-color: #rrggbb"
, it does the trick, but it also affects scrollbars. How to set just the text bg color? -
I've tried
setStyleSheet
with"background-color: #rrggbb"
, it does the trick, but it also affects scrollbars. How to set just the text bg color?Hi!
QPalette p = ui->plainTextEdit->palette(); p.setColor(QPalette::Active, QPalette::Base, Qt::black); ui->plainTextEdit->setPalette(p); ui->plainTextEdit->setBackgroundVisible(false);
-
I've tried
setStyleSheet
with"background-color: #rrggbb"
, it does the trick, but it also affects scrollbars. How to set just the text bg color?If you want to change only the color of the entire viewport background (except scrollbar), must specify a selector.
like this:
ui->plainTextEdit->setStyleSheet("QPlainTextEdit {background-color: #rrggbb;}")
And if you want to set only the text background color,
like this:
QTextCharFormat fmt; fmt.setBackground(QBrush(Qt::yellow)); ui->plainTextEdit->mergeCurrentCharFormat(fmt);
-
If you want to change only the color of the entire viewport background (except scrollbar), must specify a selector.
like this:
ui->plainTextEdit->setStyleSheet("QPlainTextEdit {background-color: #rrggbb;}")
And if you want to set only the text background color,
like this:
QTextCharFormat fmt; fmt.setBackground(QBrush(Qt::yellow)); ui->plainTextEdit->mergeCurrentCharFormat(fmt);