QTextDocument and background-images
Hi,
I copy the code from the tutorial:
Tutorial
It works's fine, but the background Image doesn't show.
Why does the <img> picture shown but the <span id='bgimage'>not ????
Is there an trick?
Here an short example:
Code:
#include <QApplication>
#include <QTextDocument>
#include <QTextBrowser>
#include <QVariant>
#include <QDebug>
int main(int argc, char *argv[])
{
// Q_INIT_RESOURCE(application);
html = "<html><head>"
"<link rel='stylesheet' type='text/css' href='format.css'>"
"</head><body>"
"Your HTML code with tags, which have classes or ids. For example "
"<span class='red'>this text is colored red</span>.<br/>"
"And you can also display images: <img src='myImage.jpg'><br/>"
"Combine css and images: <span id='bgimage'>foo bar</span>"
"</body></html>";
// Your CSS code
css = "span.red { color:#DE0000; } "
"span#bgimage { background-image: url('myImage.jpg');} ";
// Crate a QTextDocument with the defined HTML, CSS and the images
/*
* This shows how to bind the images, where the name for QUrl is the same name
* which you use in your HTML and CSS. In QPixmap just use the normal syntax of
* the Qt resource system.
*/
/*
* And now bind the css, which you have defined in the QString css.
*/
doc->setHtml( html ); // binds the HTML to the QTextDocument
/*
* This QTextDocument can now set to any QTextBrowser.
*/
tb->setDocument( doc );
tb->show();
return app.exec();
}