Override mousePressEvent instead of event

This commit is contained in:
Florian Bruhin 2014-04-23 07:32:27 +02:00
parent 2c5bb6a413
commit a67ed4d054

View File

@ -20,7 +20,7 @@
import logging import logging
import functools import functools
from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QEvent from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt
from PyQt5.QtWidgets import QApplication from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebKit import QWebSettings from PyQt5.QtWebKit import QWebSettings
from PyQt5.QtWebKitWidgets import QWebView, QWebPage from PyQt5.QtWebKitWidgets import QWebView, QWebPage
@ -248,10 +248,10 @@ class BrowserTab(QWebView):
# Let superclass handle the event # Let superclass handle the event
return super().paintEvent(e) return super().paintEvent(e)
def event(self, e): def mousePressEvent(self, e):
"""Check if a link was clicked with the middle button or Ctrl. """Check if a link was clicked with the middle button or Ctrl.
Extend the superclass event(). Extend the superclass mousePressEvent().
This also is a bit of a hack, but it seems it's the only possible way. This also is a bit of a hack, but it seems it's the only possible way.
Set the _open_target attribute accordingly. Set the _open_target attribute accordingly.
@ -260,9 +260,8 @@ class BrowserTab(QWebView):
e: The arrived event. e: The arrived event.
Return: Return:
The superclass event return value. The superclass return value.
""" """
if e.type() in [QEvent.MouseButtonPress, QEvent.MouseButtonDblClick]:
if self._force_open_target is not None: if self._force_open_target is not None:
self._open_target = self._force_open_target self._open_target = self._force_open_target
self._force_open_target = None self._force_open_target = None
@ -277,4 +276,4 @@ class BrowserTab(QWebView):
logging.debug("Setting target: {}".format(self._open_target)) logging.debug("Setting target: {}".format(self._open_target))
else: else:
self._open_target = "normal" self._open_target = "normal"
return super().event(e) return super().mousePressEvent(e)