【发布时间】:2016-03-08 03:24:17
【问题描述】:
我想用QTextEdit(只读模式)来显示一个可点击的超链接,我曾经这样做过
QTextEdit *textEdit = new QTextEdit;
QTextCursor cursor(textEdit->document());
textEdit->setTextCursor(cursor);
cursor->insertHtml("<a href=\"www.google.com\" >Google</a>");
textEdit->show();
此代码会将 Google 显示为超链接,但无法点击。
如果我用过
QTextEdit *textEdit = new QTextEdit;
QTextCursor cursor(textEdit->document());
textEdit->setTextCursor(cursor);
QTextCharFormat linkFormat = cursor.charFormat();
linkFormat.setAnchor(true);
linkFormat.setAnchorHref("http://www.google.com");
linkFormat.setAnchorName("Google");
cursor.insertText("Google", linkFormat);
然后什么都没有发生。 “Google”只是普通文本。
请帮我插入指向QTextEdit的可点击超链接。
【问题讨论】: