Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. QtWebKit - how to get information about <label> element on which user clicked
Forum Updated to NodeBB v4.3 + New Features

QtWebKit - how to get information about <label> element on which user clicked

Scheduled Pinned Locked Moved Qt WebKit
6 Posts 2 Posters 3.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    guziemic
    wrote on last edited by
    #1

    Hi,

    I have such web page

    @
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xml:lang="de" lang="de"><head>
    <title>Form test</title>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    </head>
    <body>
    <form action="../PChecker" method="get">
    <br><br><label for="male">Male</label>
    <input class="noborder" name="radiobuttonMH" value="male" type="radio" id="male">
    <br><label for="female">Female</label>
    <input class="noborder" name="radiobuttonMH" value="female" type="radio" id="female">
    <br>
    </form></body></html>
    @

    That in browser looks following
    !http://i1177.photobucket.com/albums/x353/michal_g81/picture.png(Picture)!

    And now my problem:
    User click on for instance Female to select radio button. This is label in HTML code. I would like to be able to get this element as QWebElement.
    So I did following
    @
    void CWebView::mousePressEvent(QGraphicsSceneMouseEvent * a_pMouseEvent)
    {
    QWebFrame * pFrame = m_oPage.frameAt(a_pMouseEvent->pos().toPoint());
    QWebHitTestResult oHitResult = pFrame->hitTestContent(a_pMouseEvent->pos().toPoint());
    QWebElement oWebElement = a_oHitResult.element();

    if (oWebElement.isNull())
    {
        //and the element is always NULL
    }
    else
    {
        //Do some action
     }
    

    }
    @

    Unfortunetly, I always have information that element is NULL. When I directly clicked on circle that it is OK.

    For simplicity I did not put here checking of pointers i.e. to frame and so on.

    Do you have an idea what can be wrong? How to get <label> as a QWebElement when the user click on it.

    Thanks.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      KA51O
      wrote on last edited by
      #2

      Did you check if the position of the mouse cursor returned by a_pMouseEvent->pos().toPoint() is correct?

      1 Reply Last reply
      0
      • G Offline
        G Offline
        guziemic
        wrote on last edited by
        #3

        Yes, position is correct.
        I can get HTML code from frame. I have also information about size (QRect) of element under cursor. Even if this element is NULL.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          KA51O
          wrote on last edited by
          #4

          Hmmm. Maybe the QWebElement of your label is interpreted as a null element. I had some trouble once appending stuff inside a QWebElement of a <header> (QWebElement::appendInside(..)), nothing was appended because the element was interpreted as a null element.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            guziemic
            wrote on last edited by
            #5

            Yes, I put this information that my <label> is interpreted as a null element. And I cannot understand why?

            1 Reply Last reply
            0
            • G Offline
              G Offline
              guziemic
              wrote on last edited by
              #6

              I look at problem also from other perspective. QWebElement from QWebHitTestResult can give information about size of element on which user make a click. I used this size to check if such element is on page.

              @
              QWebElementCollection labelsCollection = a_pWebFrame->findAllElements("label");
              if (0 == labelsCollection.count())
              {
              //lack of labels
              }
              else
              {
              foreach (QWebElement element, labelsCollection)
              {
              QRect modification = element.geometry();
              modification.adjust(0,1,0,0); //add 1 to y axis, because geometry returns smaller size than real geometry

                  //a_elementRect is rectangle from hit test
                  if (a_elementRect == modification)
                  {
                     retValElement = element; //we have label that was previously null
                      break;
                  }
              }
              

              }
              @

              I am able to find <label> in such way and after assignment to QWebElement I can do all operation on it, as it is not null element.

              I used it as a workaround, but I do not think that it is a perfect solution.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved