我正在使用QTextDocument生成PDF报告。我只是无法弄清楚如何在QTextDocument中插入URL。我甚至不知道它是否得到支持。任何帮助都非常感谢。
答案 0 :(得分:1)
也许使用HTML:
// Your HTML code
QString html;
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.png'><br/>"
"Combine css and images: <span id='bgimage'>foo bar</span>"
"</body></html>";
// Your CSS code
QString css;
css = "span.red { color:#DE0000; } "
"span#bgimage { background-image: url('bg.png'); } ";
// Crate a QTextDocument with the defined HTML, CSS and the images
QTextDocument *doc = new QTextDocument;
/*
* And now bind the css, which you have defined in the QString css.
*/
doc->addResource( QTextDocument::StyleSheetResource, QUrl( "format.css" ), css );
doc->setHtml( html ); // binds the HTML to the QTextDocument