Hi there, when user double clicks on QTextCursor in QTextEdit, I am looking for a way to get a string from that QTextCursor.
def __init__(self, parent=None):
#some initialization
def insert(self, name):
cursor = self.textCursor()
path = "image/icons/Messenger_blue32.png"
image = icon.toImage()
cursor.insertImage(image)
cursor.insertText(name)
self.setTextCursor(cursor)
self.ensureCursorVisible()
end = "<br />"
self.textCursor().insertFragment(fragment)
def mouseDoubleClickEvent(self,event):
cursor = self.cursorForPosition(event.pos())
BlockUnderCursor = 2
cursor.select(BlockUnderCursor)
name = cursor.selectedText()
print name
class ContactsView(QtGui.QTextEdit):
def __init__(self, parent=None):
QtGui.QTextEdit.__init__(self, parent)
#some initialization
def insert(self, name):
cursor = self.textCursor()
path = "image/icons/Messenger_blue32.png"
icon = QtGui.QPixmap(path)
image = icon.toImage()
cursor.insertImage(image)
cursor.insertText(name)
self.setTextCursor(cursor)
self.ensureCursorVisible()
end = "<br />"
fragment = QtGui.QTextDocumentFragment.fromHtml(end)
self.textCursor().insertFragment(fragment)
def mouseDoubleClickEvent(self,event):
cursor = self.cursorForPosition(event.pos())
BlockUnderCursor = 2
cursor.select(BlockUnderCursor)
name = cursor.selectedText()
print name
To copy to clipboard, switch view to plain text mode
and when I run this program, I am getting this run time error;
ContactsView.py", line 24, in mouseDoubleClickEvent
print name
UnicodeEncodeError: 'ascii' codec can't encode character u'\ufffc' in position 0: ordinal not in range(128)
I believe I am getting this error because there are more than strings in cursor.
all I am interested is that I want to get a string from TextCursor whenever it is double clicked.
Could anyone give me an advise? any inputs would be very appreciated.
thank you for consideration.
regards
Naoya
Bookmarks