Qt:如何访问 WebKit 页面上的实际小部件?

发布于 2024-09-02 22:03:27 字数 131 浏览 4 评论 0原文

有没有办法使用 Qt 访问 WebKit 页面上由 INPUTSELECT 生成的小部件?

与此相关的是,WebKit 是否提供这些小部件,或者是否委托给 Qt 来生成它们?

Is there a way to access the widgets generated by INPUT and SELECT on a page in WebKit, using Qt?

On a related note, does WebKit provide these widgets, or does it delegate back to Qt to generate them?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

昔日梦未散 2024-09-09 22:03:27

没有“小部件”。较新的浏览器会自行渲染所有元素以允许叠加等。

如果您想操作它们,请使用 DOM。

There are no "widgets". Newer browsers render all elements themselves to allow overlays etc.

If you want to manipulate them use the DOM.

×眷恋的温暖 2024-09-09 22:03:27

QWebView 中的所有内容都不使用传统的 Qt 小部件系统。它只是 HTML,由 WebKit 呈现。但是您可以使用 evalJS 函数访问 html。代码示例:

 QString Widget::evalJS(const QString &js)
 {
     QWebFrame *frame = ui->webView->page()->mainFrame();
     return frame->evaluateJavaScript(js).toString();
 }

 evalJS(QString("document.forms[\"f\"].text.value = \"%1\";").arg(fromText));

 evalJS(QString("document.forms[\"f\"].langSelect.value = \"%1\";").arg(langText));

 evalJS(QString("translate()"));

 QString from = evalJS("document.forms[\"f\"].text.value");
 QString translation = evalJS("document.forms[\"f\"].translation.value");
 ui->textEditTo->setText(translation);

Everything inside in QWebView does not use the conventional Qt widget system. It's only HTML, rendered by WebKit. But you can access to html by using the evalJS function. Example of code:

 QString Widget::evalJS(const QString &js)
 {
     QWebFrame *frame = ui->webView->page()->mainFrame();
     return frame->evaluateJavaScript(js).toString();
 }

 evalJS(QString("document.forms[\"f\"].text.value = \"%1\";").arg(fromText));

 evalJS(QString("document.forms[\"f\"].langSelect.value = \"%1\";").arg(langText));

 evalJS(QString("translate()"));

 QString from = evalJS("document.forms[\"f\"].text.value");
 QString translation = evalJS("document.forms[\"f\"].translation.value");
 ui->textEditTo->setText(translation);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文