Nominate our 2022 Qt Champions!

How to mimic in QWebKit something like "Inspect" in firebug?

  • Hello all
    i like to be able to mimic the function of firebug ( browser plugin ) inspect functionality .
    i found something that called inspector in webkit , but i have no idea how to implement it
    or if its even related to this .

  • You do not need to implement inspector, it is already in webkit.
    simply enable developer extras:
    QWebView::settings()->globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
    and call inspector when you need it:
    QWebInspector * m_inspector = new QWebInspector(0);
    m_inspector->setPage(this->page());//set pointer to QWebPage which you want to inspect...
    QTimer::singleShot(0, m_inspector,SLOT(show()));

  • Thanks for the replay , what i want is to be able to right click with the mouse and then the selected html element will be highlighted and the element innerHTML will content will be available to me , i need the general idea on how to do this

  • Oh OK. I think it is possible....

    First, reimplement:
    @void QWebView::mousePressEvent(QMouseEvent * ev)@
    you then can get position of click from QMouseEvent

    using this position get QWebFrame from QWebPage of your QWebView:
    QWebFrame * frameAt(const QPoint & pos) const

    Do an hint test on this QWebFrame:
    QWebHitTestResult QWebFrame::hitTestContent(const QPoint & pos) const

    in returned QWebHitTestResult you will get your hint test result and QWebElement under this position:
    QWebElement element() const

    after that examine QWebElement for any kind of information in this DOM element.

    Should work, but i didn't tested it... but I think the standard WebKit inspector is doing it exactly this way...

Log in to reply