0

I'm having trouble detecting the clicked element in a qtwebkit qwebview.

Don't know why but when looking for an attribute, I get nothing back when clicking on text in my document

void APP_Orders::contextMenuEvent(QContextMenuEvent *event)
{
        QWebHitTestResult hit = page()->mainFrame()->hitTestContent(event->pos());
        QWebElement hitElement = hit.element();
        QString ctx = hitElement.attribute("ctx","none");
        while(ctx == "none")
        {
            hitElement = hitElement.parent();
            ctx = hitElement.attribute("ctx","none");
        }


        qDebug() << ctx;
}

In my document, I have a ctx attribute on the body. Wherever I click, I get the body's ctx attribute in the debug that's the expected behaviour but when I click on text, It looks like it's not in the document... the app crashes after being in an infinite loop. even when I look at the xml content or parents, grandparents grangranparents xml content is always an empty string...

Any idea why???

Vincent Duprez
  • 3,772
  • 8
  • 36
  • 76

1 Answers1

1

Ok, a colleague found this workaround. sharing it if someone needs it...

void APP_Orders::contextMenuEvent(QContextMenuEvent *event)
{
        QWebHitTestResult hit = page()->mainFrame()->hitTestContent(event->pos());
        QWebElement hitElement = hit.element();
        QString ctx = hitElement.attribute("ctx","none");
        if(ctx == "")
        {
            hitElement = hit.enclosingBlockElement();
            ctx = hitElement.attribute("ctx","none");
        }
        while(ctx == "none")
        {
            hitElement = hitElement.parent();
            ctx = hitElement.attribute("ctx","none");
        }


        qDebug() << ctx;
}
Vincent Duprez
  • 3,772
  • 8
  • 36
  • 76