2014-06-18 33 views
2

我正在使用QTextDocument生成PDF報告。我只是無法弄清楚如何在QTextDocument中插入URL。我甚至不知道它是否被支持。任何幫助,高度讚賞。在QTextDocument中插入URL

回答

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