PDA

View Full Version : "hitTestCOntent" function failed for <span> and <a> HTML Tags



kkpatel
6th December 2012, 16:54
I have implemented a code to get a name of html tag from webpage where user clicked.

To get tag name, I have used “hitTestContent” function. Below is the code which I used in Qt 4.8 demo browser:-


void WebView::mousePressEvent(QMouseEvent *event)
{
m_page->m_pressedButtons = event->buttons();
m_page->m_keyboardModifiers = event->modifiers();
QWebView::mousePressEvent(event);
QWebFrame *pFrame = m_page->frameAt(event->pos());
QWebHitTestResult HitResult = pFrame->hitTestContent(event->pos());
QWebElement WebElement = HitResult.element();

if (!WebElement.isNull()) //Control does not enter in this loop for <span> tag
{
qDebug() << "Mouse Pressed:" << WebElement.localName() << WebElement.parent().localName();
}
}

I am able to get almost all tag name when I clicked on webpage. But this code fails for <span> tag and <a> tag. I have checked this in Qt 4.7, but the result is same.
Please help to solve above problem.