src/eric7/EricWidgets/EricSpellCheckedTextEdit.py

branch
eric7
changeset 9643
10839ab864e0
parent 9600
367d1b4fcca8
child 9653
e67609152c5e
diff -r a0f7800fbfcb -r 10839ab864e0 src/eric7/EricWidgets/EricSpellCheckedTextEdit.py
--- a/src/eric7/EricWidgets/EricSpellCheckedTextEdit.py	Fri Dec 23 10:58:36 2022 +0100
+++ b/src/eric7/EricWidgets/EricSpellCheckedTextEdit.py	Fri Dec 23 11:35:54 2022 +0100
@@ -21,7 +21,7 @@
 except ImportError:
     ENCHANT_AVAILABLE = False
 
-from PyQt6.QtCore import QCoreApplication, Qt, pyqtSlot
+from PyQt6.QtCore import QCoreApplication, QPoint, Qt, pyqtSlot
 from PyQt6.QtGui import (
     QAction,
     QActionGroup,
@@ -78,16 +78,16 @@
 
             self.__highlighter.setDict(spellDict)
 
-        def contextMenuEvent(self, evt):
+        @pyqtSlot(QPoint)
+        def _showContextMenu(self, pos):
             """
-            Protected method to handle context menu events to add a spelling
-            suggestions submenu.
+            Protected slot to show a context menu.
 
-            @param evt reference to the context menu event
-            @type QContextMenuEvent
+            @param pos position for the context menu
+            @type QPoint
             """
-            menu = self.__createSpellcheckContextMenu(evt.pos())
-            menu.exec(evt.globalPos())
+            menu = self.__createSpellcheckContextMenu(pos)
+            menu.exec(self.mapToGlobal(pos))
 
         def __createSpellcheckContextMenu(self, pos):
             """
@@ -576,6 +576,16 @@
             """
             pass
 
+        @pyqtSlot(QPoint)
+        def _showContextMenu(self, pos):
+            """
+            Protected slot to show a context menu.
+
+            @param pos position for the context menu
+            @type QPoint
+            """
+            pass
+
         def setFormat(self, formatName):
             """
             Public method to set the document format.
@@ -658,6 +668,9 @@
         QPlainTextEdit.__init__(self, *args)
         SpellCheckMixin.__init__(self)
 
+        self.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
+        self.customContextMenuRequested.connect(self._showContextMenu)
+
 
 class EricSpellCheckedTextEdit(QTextEdit, SpellCheckMixin):
     """
@@ -676,6 +689,9 @@
 
         self.setFormat("html")
 
+        self.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
+        self.customContextMenuRequested.connect(self._showContextMenu)
+
     def setAcceptRichText(self, accept):
         """
         Public method to set the text edit mode.

eric ide

mercurial