views:

280

answers:

2

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?

+1  A: 

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

If you want to manipulate them use the DOM.

Axel Gneiting
Doesn't QtWebKit use the Qt widgets and pain system to draw the web page? QtWebKit depends on QtGui.
iconiK
What about the interactive elements, like the text fields generated by INPUT? They need to store information about selection, caret position, etc., so wouldn't they be some type of "widget" object?
Jen
@iconiK, @Jen: No. The lowest widget is the `QWebView` itself. Everything inside that does not use the conventional Qt widget system. It's rendered by [WebKit](http://webkit.org/).
Troubadour
@Troubadour, oh okay then. Well I guess there isn't any convenient way to manipulate the elements outside of QWebElement.
iconiK
But... doesn't Qt provide callback methods to render each element?
Jen
+1  A: 

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