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

J Barchan jnbarchan at gmail.com
Tue Jul 17 15:23:12 BST 2018


On 17 July 2018 at 15:05, Andy Stewart <lazycat.manatee at gmail.com> wrote:

> 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
>
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
>

​
I stand to be corrected, but I do not believe ​you can do this any longer
when you move from `QWebKit` to `QWebEngine`....


-- 
Kindest,
Jonathan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180717/f7e45ade/attachment.html>


More information about the PyQt mailing list