Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt QPlainTextEdit background

Tags:

c++

qt

I want to change the background color of a QPlainTextEdit, how do I do this?

like image 382
deuces Avatar asked Oct 06 '09 23:10

deuces


3 Answers

Modify the palette of your plain text edit. Sample program:

#include <QApplication>
#include <QPlainTextEdit>

int main(int argc, char* argv[])
{
  QApplication app(argc, argv);

  QPlainTextEdit edit;
  QPalette p = edit.palette();

  p.setColor(QPalette::Active, QPalette::Base, Qt::red);
  p.setColor(QPalette::Inactive, QPalette::Base, Qt::red);

  edit.setPalette(p);

  edit.show();
  return app.exec();
}

Substitute whatever color you want, of course.

like image 146
Bill Avatar answered Nov 11 '22 20:11

Bill


If QPlainTextEdit supports style sheets, you could do it like this:

myPlainTextEdit->setStyleSheet("background-color: yellow");

or

qApp->setStyleSheet("QPlainTextEdit {background-color: yellow}");
like image 38
Sam Dutton Avatar answered Nov 11 '22 20:11

Sam Dutton


Slightly confusingly they call it role rather than colour/color.

https://doc.qt.io/qt-5/qwidget.html#setBackgroundRole

hint - if you can't find a function for a particular control, click on show inherited members - most general settings are in qWidget which is the basis for eveything drawn on screen.

like image 3
Martin Beckett Avatar answered Nov 11 '22 20:11

Martin Beckett