--- a/src/eric7/WebBrowser/WebBrowserView.py Fri Dec 23 10:58:36 2022 +0100 +++ b/src/eric7/WebBrowser/WebBrowserView.py Fri Dec 23 11:35:54 2022 +0100 @@ -28,14 +28,7 @@ pyqtSignal, pyqtSlot, ) -from PyQt6.QtGui import ( - QClipboard, - QContextMenuEvent, - QCursor, - QDesktopServices, - QIcon, - QPixmap, -) +from PyQt6.QtGui import QClipboard, QCursor, QDesktopServices, QIcon, QPixmap from PyQt6.QtWebEngineCore import QWebEngineDownloadRequest, QWebEnginePage from PyQt6.QtWebEngineWidgets import QWebEngineView from PyQt6.QtWidgets import QApplication, QDialog, QMenu, QStyle @@ -141,6 +134,9 @@ self.__currentZoom = 100 self.__zoomLevels = WebBrowserView.ZoomLevels[:] + self.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) + self.customContextMenuRequested.connect(self.__showContextMenu) + self.iconUrlChanged.connect(self.__iconUrlChanged) self.urlChanged.connect(self.__urlChanged) self.page().linkHovered.connect(self.__linkHovered) @@ -182,7 +178,9 @@ self.__page.safeBrowsingAbort.connect(self.safeBrowsingAbort) self.__page.safeBrowsingBad.connect(self.safeBrowsingBad) self.__page.printPageRequested.connect(self.__printPage) - self.__page.quotaRequested.connect(self.__quotaRequested) + with contextlib.suppress(AttributeError): + # deprecated with Qt 6.5+ + self.__page.quotaRequested.connect(self.__quotaRequested) with contextlib.suppress(AttributeError): # Qt 6.4+ self.__page.fileSystemAccessRequested.connect( @@ -557,33 +555,17 @@ ) ) - def contextMenuEvent(self, evt): - """ - Protected method called to create a context menu. - - This method is overridden from QWebEngineView. - - @param evt reference to the context menu event object - (QContextMenuEvent) + @pyqtSlot(QPoint) + def __showContextMenu(self, pos): """ - pos = evt.pos() - reason = evt.reason() - QTimer.singleShot( - 0, functools.partial(self._contextMenuEvent, QContextMenuEvent(reason, pos)) - ) - # needs to be done this way because contextMenuEvent is blocking - # the main loop + Private slot to show a context menu. - def _contextMenuEvent(self, evt): - """ - Protected method called to create a context menu. - - @param evt reference to the context menu event object - (QContextMenuEvent) + @param pos position for the context menu + @type QPoint """ self.__menu.clear() - hitTest = self.page().hitTestContent(evt.pos()) + hitTest = self.page().hitTestContent(pos) self.__createContextMenu(self.__menu, hitTest) @@ -599,8 +581,7 @@ ) if not self.__menu.isEmpty(): - pos = evt.globalPos() - self.__menu.popup(QPoint(pos.x(), pos.y() + 1)) + self.__menu.popup(self.mapToGlobal(pos)) def __createContextMenu(self, menu, hitTest): """ @@ -2303,6 +2284,7 @@ ## Methods below implement slots for Qt 5.11+ ########################################################################### + # deprecated with Qt 6.5+ @pyqtSlot("QWebEngineQuotaRequest") def __quotaRequested(self, quotaRequest): """