diff --git a/q3dwebkitview.py b/q3dwebkitview.py index 59e0b59b..629d02c5 100644 --- a/q3dwebkitview.py +++ b/q3dwebkitview.py @@ -29,6 +29,8 @@ def __init__(self, parent=None): QWebPage.__init__(self, parent) Q3DWebPageCommon.__init__(self) + self.isWebEnginePage = False + def setup(self, settings, wnd=None, exportMode=False): """wnd: Q3DWindow or None (off-screen mode)""" Q3DWebPageCommon.setup(self, settings, wnd, exportMode) diff --git a/q3dwebviewcommon.py b/q3dwebviewcommon.py index 3bd83d9c..5ac5bc82 100644 --- a/q3dwebviewcommon.py +++ b/q3dwebviewcommon.py @@ -24,7 +24,6 @@ class Q3DWebPageCommon: def __init__(self, _=None): - self.isWebEnginePage = False self.loadedScripts = {} if DEBUG_MODE == 2: diff --git a/tests/gui/test_gui.py b/tests/gui/test_gui.py index d27123c6..bb0c3a77 100644 --- a/tests/gui/test_gui.py +++ b/tests/gui/test_gui.py @@ -4,10 +4,11 @@ # begin: 2023-10-16 import os -from PyQt5.QtCore import Qt, QEventLoop, QPoint, QTimer -from PyQt5.QtWidgets import QDialogButtonBox, QMessageBox +from PyQt5.QtCore import Qt, QEvent, QEventLoop, QPoint, QTimer +from PyQt5.QtGui import QMouseEvent +from PyQt5.QtWidgets import QDialogButtonBox, QMessageBox, QWidget from PyQt5.QtTest import QTest -from qgis.core import QgsProject, QgsRectangle +from qgis.core import QgsApplication, QgsProject, QgsRectangle from qgis.testing import unittest from Qgis2threejs.q3dconst import Script @@ -58,7 +59,19 @@ def loadSettings(self, filename): def mouseClick(self, x, y): self.WND.runScript("showMarker({}, {}, 400)".format(x, y)) self.sleep(500) - QTest.mouseClick(self.WND.ui.webView, Qt.LeftButton, pos=QPoint(x, y)) + + pos = QPoint(x, y) + w = self.WND.ui.webView + + if w._page.isWebEnginePage: + w = w.findChild(QWidget) + press = QMouseEvent(QEvent.MouseButtonPress, pos, Qt.LeftButton, Qt.NoButton, Qt.NoModifier) + release = QMouseEvent(QEvent.MouseButtonRelease, pos, Qt.LeftButton, Qt.NoButton, Qt.NoModifier) + + QgsApplication.postEvent(w, press) + QgsApplication.postEvent(w, release) + else: + QTest.mouseClick(w, Qt.LeftButton, pos=pos) @classmethod def sleep(cls, msec=500):