PDA

View Full Version : Take mouse right click position on QWebview after scrolling



ALICE_QT
19th August 2015, 09:44
The problem: if the text is big, it is scrolling to the end, but if i want to take elements of DOM tree under mouse right click, it take the elements of the beginning of page.
How can i take elements of DOM tree of visible part of document?

menuRequested(const QPoint &pos)
{
QWebFrame * element = webView->page()->frameAt(pos);
QWebElementCollection els = element->findAllElements("div.message");
messageId = -1;

for(QWebElementCollection::const_iterator it=els.constBegin();it!=els.constEnd();it++)
{
const QWebElement test = *it;
QRect rect = test.geometry();
if(rect.contains(pos))
{
if(test.hasAttribute("id"))
messageId= test.attribute("id").toInt();
break;
}
}
if (messageId != -1 )
{
menu->exec(webView->mapToGlobal(pos));
}
}