Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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

If you want to manipulate them use the DOM.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top