[PyQt] How to customize link click behavier of QWebEngine?

Andy Stewart lazycat.manatee at gmail.com
Tue Jul 17 15:05:37 BST 2018


Hi guys.

In QWebKit, I just use need customize function
QWebPage:acceptNavigationRequest to change link click behaver:

1. Click  to open link in current tab
2. Tab + Click to open link in new tab

like below code:

class WebPage(QWebPage):
>     open_url_in_new_tab = QtCore.pyqtSignal(str)
>     def __init__(self):
>         super(WebPage, self).__init__()
>     def acceptNavigationRequest(self, frame, request, type):
>         modifiers = QApplication.keyboardModifiers()
>         # Handle myself if got user event.
>         if type == QWebPage.NavigationTypeLinkClicked:
>             if modifiers == Qt.ControlModifier:
>                 self.open_url_in_new_tab.emit(request.url().toString())
>             else:
>                 self.view().load(request.url())
>             # Return False to stop default behavior.
>             return False
>         # # Otherwise, use default behavior.
>         return QWebPage.acceptNavigationRequest(self, frame, request, type)


My question is, how customize click behavior in QWebEngine?

I have search Google and StackOverflow, noting can help.

Thanks for your help!

 -- Andy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180717/84b7f4bf/attachment.html>


More information about the PyQt mailing list