首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在QTextDocument中插入URL

在QTextDocument中插入URL
EN

Stack Overflow用户
提问于 2014-06-18 09:01:02
回答 1查看 1K关注 0票数 2

我正在使用QTextDocument生成PDF报告。我只是不知道如何在QTextDocument中插入URL。我甚至不知道它是否被支持。任何帮助都是非常感谢的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-18 09:12:21

也许使用HTML:

代码语言:javascript
复制
// 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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24281321

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档