Qt World Summit: Register Today!

How to test content of a mouse-click in QWebEnginePage?

  • In an app using QWebView/QWebPage, one can ask the QWebPage for its mainFrame() or currentFrame(), getting a QWebFrame.

    The QWebFrame offers the method hitTestContent(pos) which tells whether the thing at that position is a URL, an image, or something else. I use this in a custom context menu for a QWebPage, to find out if the item right-clicked for the context menu was a URL.

    It seems the QWebEnginePage does not offer access to a frame, or any other way of finding out the content under a mouse click. One can create a custom context menu, but I do not see how to determine if the right-click fell on a URL or not. Is this available?

  • Let me just add that if you right-click in a Chrome browser window, the context menu is quite different depending on whether you right-click on a link ("Open Link in New Tab," etc), on an image ("Save Image as..." etc), on open text ("Back", "Reload" etc), even different again on an image that is inside a link.

    So the browser code itself certainly has all the details of the target under a right-click. With QWebPage that information is available. I hope that it is available from QWebEnginePage and that I have just overlooked it.

Log in to reply