I want to change my webview's background image, color and font color. I tried setBackgroundRole method but it only have few color. It doesn't have the color that I want. And I don't find how to set font color and background image. Do you have any ideas to solve this thing?
Asked
Active
Viewed 2,507 times
3 Answers
0
use setHtml function
QString htmlhead = "<head><style>body {\n background-color: #eee;\nbackground-image: url("+QUrl("qrc:/new/prefix1/back.png").toString()+");";
ui->webView->setHtml(htmlhead);

Michika Iranga Perera
- 1,346
- 13
- 8
0
Use html for that, QWebView is just a container for QWebPage, where you can set all you need in page's html code.

Raiv
- 5,731
- 1
- 33
- 51
-
Thanks for your reply but it's not that I want. Ex: I want when I load some text to Qwebview, the text will use my color to display and it will display on my background. – Eagle King Jun 22 '11 at 09:46
0
Use QWidget::setPalette()
to set your own QPalette
. With this you can freely choose colors for each role.
To have an image as a background you would have to derive your own class from QWebView
and override paintEvent()
I think.

Steffen
- 2,888
- 19
- 19
-
1`QPalette p = ui->webView->palette(); QPixmap pixmap1("D:/duc2.jpg"); QRect rect = ui->webView->rect(); QSize size(rect.width() , rect.height()); QPixmap pixmap(pixmap1.scaled(size)); p.setBrush(QPalette::Background, pixmap); ui->webView->setPalette(p);` This is my code to set webview's background but I don't see my background image on webview. Is there something wrong ? – Eagle King Jun 22 '11 at 11:04
-
Looks like it might work. Did you use setBackgroundRole() in addition somewhere? Although I think it should still work: QPalette::Background is deprecated, QPalette::Window is the new enum for it. – Steffen Jun 22 '11 at 11:13
-
`ui->webView->setBackgroundRole(QPalette::Window);` I used setBackgroundRole() method like that. I also modified it `ui->webView->setBackgroundRole(QPalette::Background);` but it didn't work. What can I do to solve this thing? – Eagle King Jun 23 '11 at 01:41
-
Yeah, it seems QWebView is a bit different than most QWidgets. I did not manage to put background picture via the QPalette in it either. I think best bet would be something like this: http://labs.qt.nokia.com/2009/06/30/transparent-qwebview-or-qwebpage/ and have your picture underneath in a different widgets. – Steffen Jun 23 '11 at 16:23