1
我有一個webView
安裝程序來顯示聊天消息。將html附加到QWebView?
我開始像這樣:
ui->webView->setHtml("<html style=\"font-family:Lucida Grande;font-size:13px;\">
<head></head>
<body style=\"padding:0px;margin:0px;\">
<div id=\"date\"style=\"position:fixed;top:0;height:40px;background-color:#ffffff;opacity:0.9;width:100%;border-bottom:1px solid #f1f1f1;\"><span style=\"display:block;color:#6d7382;padding-top:12px;padding-left:14px;\">friday</span></div>
<div style=\"padding:12px;background-color:#f5f5f5;display:block;border-bottom:1px solid #f1f1f1;border-top:1px solid #f1f1f1;\"><div style=\"color:#606775;font-weight:bold;\">Bill</div><div style=\"color:#5a5a5a;\"><p>Hello</p></div></div>
</body></html>");
(上面的代碼是在QT全部在一行,我只需點擊進入,使其更容易讀到這裏)
現在我試圖找出如何附加div's
它以新的聊天消息的形式。
試圖附加這樣的:
QString html = "<div>Test test</div>";
QString js = QString("document.execCommand('InsertHTML',false,'%1');").arg(html);
ui->webView->page()->mainFrame()->evaluateJavaScript(js);
切換出來的日期正常工作,我是這樣做的:
// Switches out the date
QWebFrame *pSource = ui->webView->page()->mainFrame();
QWebElement dateDiv = pSource->findFirstElement("#date");
dateDiv.replace("<div id=\"date\"style=\"position:fixed;top:0;height:40px;background-color:#ffffff;opacity:0.9;width:100%;border-bottom:1px solid #f1f1f1;\"><span style=\"display:block;color:#6d7382;padding-top:12px;padding-left:14px;\">sunday</span></div>");
但是插入新div's
是我不能去上班。 任何想法我做錯了什麼?順便說一句
ui->webView->page()->mainFrame()->documentElement().appendInside(html);
:
這樣的作品,但它內部的'body'標籤以外,可我莫名其妙地作出這樣的插入到了body標籤? – user3082584