PyQt5. How to get cursor position in QTextEdit connected with ContextMenu?

Clash Royale CLAN TAG#URR8PPPPyQt5. How to get cursor position in QTextEdit connected with ContextMenu?
I try to get cursor position in QTextEdit:
QTextEdit
class CustomEdit(QTextEdit):
self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.cursor = self.textCursor()
self.menu = None
self.customContextMenuRequested.connect(self.create_menu)
def create_menu(self, pos):
self.menu = QMenu()
self.menu.addSeparator()
func = self.menu.addAction(u'function')
action = self.menu.exec_(self.viewport().mapToGlobal(pos))
if action == func:
self.func()
def func(self)
print(self.cursor.positionInBlock())
but it doesn't work.
It returns wrong number that not correlated with cursor position
– tanitrielle
19 mins ago
Is that your real code? Why do you pass
pos tofunc if that function does not require arguments?, what is self?– eyllanesc
18 mins ago
pos
func
self
I correct copy past from project. Self - it is argument of this function as part of class that inherited from QTextEdit
– tanitrielle
15 mins ago
pyqt4 or pyqt5??
– eyllanesc
12 mins ago
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
What does it mean that it does not work?
– eyllanesc
21 mins ago