thank you for your reply, wysota. yes that works!!
here is my code for anyone who had a similar problem.
def __init__(self,Ui_MainWindow, parent=None):
self.setReadOnly(True)
self.setAcceptRichText(True)
def insert(self, string,emoticonList):
cursor = self.textCursor()
if not emoticonList:
cursor.insertText(string)
else:
ls = shlex.split(str(string))
for word in ls:
for emoticon in emoticonList[:]:
if word == emoticon:
path = "image/emoticons/" + word
image = icon.toImage()
cursor.insertImage(image)
else:
cursor.insertText(word + " ")
self.setTextCursor(cursor)
end = "<br>"
self.textCursor().insertFragment(fragment)
def insertReceiveMessage(self, msg):
cursor = self.textCursor()
cursor.insertText(msg)
self.setTextCursor(cursor)
end = "<br>"
self.textCursor().insertFragment(fragment)
class TextView(QtGui.QTextEdit):
def __init__(self,Ui_MainWindow, parent=None):
QtGui.QTextEdit.__init__(self, parent)
self.setReadOnly(True)
self.setAcceptRichText(True)
def insert(self, string,emoticonList):
cursor = self.textCursor()
if not emoticonList:
cursor.insertText(string)
else:
ls = shlex.split(str(string))
for word in ls:
for emoticon in emoticonList[:]:
if word == emoticon:
path = "image/emoticons/" + word
icon = QtGui.QPixmap(path)
image = icon.toImage()
cursor.insertImage(image)
else:
cursor.insertText(word + " ")
self.setTextCursor(cursor)
end = "<br>"
fragment = QtGui.QTextDocumentFragment.fromHtml(end)
self.textCursor().insertFragment(fragment)
def insertReceiveMessage(self, msg):
cursor = self.textCursor()
cursor.insertText(msg)
self.setTextCursor(cursor)
end = "<br>"
fragment = QtGui.QTextDocumentFragment.fromHtml(end)
self.textCursor().insertFragment(fragment)
To copy to clipboard, switch view to plain text mode
thank you so much, wysota!
Bookmarks