Qt how to insert html into an editable QWebView at the cursor position?

帅比萌擦擦* 提交于 2019-12-06 07:31:07

Use execCommand with InsertHTML :

QString html = "<div>Some text</div>";
QString js = QString("document.execCommand('InsertHTML',false,'%1');").arg(html);
webview->page()->mainFrame()->evaluateJavaScript(js);

And if there are single quote characters in the HTML snippet, make sure you quote them with a backslash, since the snippet is injected through a JS string.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!