简体   繁体   中英

Qt: How can I access the actual widgets on a page in WebKit?

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?

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

If you want to manipulate them use the DOM.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM