[webkit-qt] [webkit-help] How to get the layout infomation use qtwebkit?

achellies achellies at 163.com
Wed Feb 23 02:01:49 PST 2011


Document* doc = frame()->document();
if (doc && doc->firstChild())


我没有用qt的版本,上述代码能够获取到所有的元素

在 2011-02-23,"周鹏" <zhoupeng19 at 126.com> 写道:


webkit-qt,你好!

    Hi guys!
    I want to get the page's layout infomation.eg:if there is a image in the page,i want to know the coordinates of  the image in the page,the background color, for text,i want to know it's font,size,and it's coordinates...
here is my code:
//traversal a dom tree
void traversal(QWebElement node)
{
    ... 
 QRect rect= node.geometry();
 printf("Start: X-%d,Y-%d  End: X-%d,Y-%d\n", ss.topLeft().x(), ss.topLeft().y(), ss.bottomRight().x(), ss.bottomRight().y() );
    ...
}
int main(int argc, char *argv[])
{
    ...
    QString content(htmlSource);
    QUrl url("file:///home/rmss/zp/");
    QApplication a(argc, argv);
    QWebView *view = new QWebView;

    QWebSettings * settings = QWebSettings::globalSettings();
    //settings->setAttribute(QWebSettings::AutoLoadImages, false);
    settings->setAttribute(QWebSettings::JavascriptEnabled, false);
    settings->setAttribute(QWebSettings::JavaEnabled, false);
    settings->setAttribute(QWebSettings::PluginsEnabled, false);
    settings->setAttribute(QWebSettings::PrivateBrowsingEnabled, true);
    settings->setDefaultTextEncoding("GB2312");

    view->setHtml(content, url);
    view->show();
 
    QWebPage* page = view->page();
    QWebFrame* frame = page->mainFrame();

    QString str = frame->renderTreeDump();
    QWebElement document = frame->documentElement();
    QWebElement body = document.findFirst("body");
    if(body .isNull())
    {
        printf("failed!\n");
        return -1;
    }
    QString info = eee.styleProperty("background-color", QWebElement::ComputedStyle);//get background color
    traversal(body );
    return 0;
}

I use "geometry" to get the location of every node,but it's not work correctly,and this program can't process page which use external css. And please tell me how to get the font,size of text.I have not much time to read the qtwebkit code because my boss want me to fininsh this job in two days. So. please tell me how to solove these problem,and if possible,give me some demo.

Apologize for my poor english!
        周鹏
        zhoupeng19 at 126.com
          2011-02-23
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-qt/attachments/20110223/f3ffc341/attachment-0001.html>


More information about the webkit-qt mailing list