Remove the 'hack' to get a word under cursor position as we can just use self.cursorForPosition()
This commit is contained in:
+2
-14
@@ -155,25 +155,13 @@ class GuiDocEditor(QTextEdit):
|
|||||||
QTextEdit.keyPressEvent(self, keyEvent)
|
QTextEdit.keyPressEvent(self, keyEvent)
|
||||||
return
|
return
|
||||||
|
|
||||||
def mousePressEvent(self, theEvent):
|
|
||||||
"""Capture right click events and rewrite them to left button event. This moves the cursor
|
|
||||||
to the location of the pointer. Needed to select the word under the right click.
|
|
||||||
Adapted from: https://nachtimwald.com/2009/08/22/qplaintextedit-with-in-line-spell-check
|
|
||||||
"""
|
|
||||||
if theEvent.button() == Qt.RightButton:
|
|
||||||
theEvent = QMouseEvent(
|
|
||||||
QEvent.MouseButtonPress, theEvent.pos(), Qt.LeftButton, Qt.LeftButton, Qt.NoModifier
|
|
||||||
)
|
|
||||||
QTextEdit.mousePressEvent(self, theEvent)
|
|
||||||
return
|
|
||||||
|
|
||||||
def contextMenuEvent(self, theEvent):
|
def contextMenuEvent(self, theEvent):
|
||||||
"""Intercept the context menu and insert spelling suggestions, if any.
|
"""Intercept the context menu and insert spelling suggestions, if any.
|
||||||
Uses the custom QAction class SpellAction from the same example code.
|
Uses the custom QAction class SpellAction from the same example code.
|
||||||
Adapted from: https://nachtimwald.com/2009/08/22/qplaintextedit-with-in-line-spell-check
|
Adapted from: https://nachtimwald.com/2009/08/22/qplaintextedit-with-in-line-spell-check
|
||||||
"""
|
"""
|
||||||
mnuSpell = self.createStandardContextMenu()
|
mnuSpell = self.createStandardContextMenu(theEvent.pos())
|
||||||
theCursor = self.textCursor()
|
theCursor = self.cursorForPosition(theEvent.pos())
|
||||||
theCursor.select(QTextCursor.WordUnderCursor)
|
theCursor.select(QTextCursor.WordUnderCursor)
|
||||||
self.setTextCursor(theCursor)
|
self.setTextCursor(theCursor)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user