delay event filter installation

Qt 5.11 doesn't initialize the focusProxy until
a page has been loaded.
This commit is contained in:
Damien Elmes 2018-10-23 16:06:56 +10:00
parent 63f2ccdb3a
commit 1af556cb8d

View File

@ -97,6 +97,7 @@ class AnkiWebView(QWebEngineView):
self._page.profile().setHttpCacheType(QWebEngineProfile.NoCache)
self.resetHandlers()
self.allowDrops = False
self._filterSet = False
QShortcut(QKeySequence("Esc"), self,
context=Qt.WidgetWithChildrenShortcut, activated=self.onEsc)
if isMac:
@ -112,8 +113,6 @@ class AnkiWebView(QWebEngineView):
QShortcut(QKeySequence("ctrl+shift+v"), self,
context=Qt.WidgetWithChildrenShortcut, activated=self.onPaste)
self.focusProxy().installEventFilter(self)
def eventFilter(self, obj, evt):
# disable pinch to zoom gesture
if isinstance(evt, QNativeGestureEvent):
@ -327,6 +326,10 @@ body {{ zoom: {}; {} }}
return False
def _onBridgeCmd(self, cmd):
if not self._filterSet:
self.focusProxy().installEventFilter(self)
self._filterSet = True
if self._shouldIgnoreWebEvent():
print("ignored late bridge cmd", cmd)
return