naoyamakino
14th July 2009, 23:30
Hi there, I am looking for a way to display image(emoticons) on QPlainTextEdit.
here is what I have done so far; this class is called by a QWidget class
import sys
from PyQt4 import QtGui
from PyQt4 import QtCore
class TextView(QtGui.QPlainTextEdit):
def __init__(self,Ui_MainWindow, parent=None):
QtGui.QPlainTextEdit.__init__(self, parent)
self.setReadOnly(True)
cursor = self.textCursor()
cursor.movePosition(QtGui.QTextCursor.NextWord, QtGui.QTextCursor.KeepAnchor)
cursor.insertText("test")
self.setTextCursor(cursor)
imageCursor = self.textCursor()
imageCursor.movePosition(QtGui.QTextCursor.NextWor d, QtGui.QTextCursor.KeepAnchor)
icon = QtGui.QPixmap("image/emoticon.png")
image = icon.toImage()
if image.isNull():
print 'null'
imageCursor.insertImage(image)
self.setTextCursor(imageCursor)
now it only displays "text" but not the image. What am I doing wrong? is there any ways to display image or icon onto QPlainTextEdit?
I would appreciate advice if anyone has encountered this or a similar issue.
here is what I have done so far; this class is called by a QWidget class
import sys
from PyQt4 import QtGui
from PyQt4 import QtCore
class TextView(QtGui.QPlainTextEdit):
def __init__(self,Ui_MainWindow, parent=None):
QtGui.QPlainTextEdit.__init__(self, parent)
self.setReadOnly(True)
cursor = self.textCursor()
cursor.movePosition(QtGui.QTextCursor.NextWord, QtGui.QTextCursor.KeepAnchor)
cursor.insertText("test")
self.setTextCursor(cursor)
imageCursor = self.textCursor()
imageCursor.movePosition(QtGui.QTextCursor.NextWor d, QtGui.QTextCursor.KeepAnchor)
icon = QtGui.QPixmap("image/emoticon.png")
image = icon.toImage()
if image.isNull():
print 'null'
imageCursor.insertImage(image)
self.setTextCursor(imageCursor)
now it only displays "text" but not the image. What am I doing wrong? is there any ways to display image or icon onto QPlainTextEdit?
I would appreciate advice if anyone has encountered this or a similar issue.