user666491
user666491

Reputation:

QTextEdit how to modify stylesheet elements from C++

I'm looking for the fastest way to modify css style for body element inside QTextEdit instance.

I tried this but it doesn't work

ui->textEdit->setStyleSheet("body {background-color: #aaa}");

I need a method that would update internal css stylesheet of the html document open inside QTextEdit.

Upvotes: 2

Views: 2326

Answers (2)

Vinicius Kamakura
Vinicius Kamakura

Reputation: 7778

You are using the correct member function QWidget::setStylesheet() if you need examples on how to apply the proper Stylsheet, Qt has some examples here

Upvotes: 1

Tim Meyer
Tim Meyer

Reputation: 12600

setStyleSheet updates the style sheet of the widget itself, not of the HTML document which is displayed by the text edit. As a QTextEdit does not have a "body" part, the line is ignored.

If you want the HTML document to use a different style sheet, you would have to modify the displayed HTML content (or rather the hidden stylesheet include line) directly

Upvotes: 2

Related Questions