N
N
Nonprogrammer2015-11-22 20:54:21
Python
Nonprogrammer, 2015-11-22 20:54:21

How to insert an image in a QTextEdit (QTextDocument) if the image is stored in bytes? PyQt4.?

Python 3.3 + PyQt4
Task: insert pictures (formulas) into text.
I know that by specifying the path to the image, you can insert it into the QTextDocument. But my pictures are stored in bytes (class bytes). I don't even have an idea how to show such images in the text. For example, I will give the following code.

import sys
from PyQt4 import QtGui

app=QtGui.QApplication(sys.argv)

editor=QtGui.QTextEdit()
editor.setGeometry(300, 200, 350, 300)
editor.show()

fin=open('formula.jpg', 'rb') # Это я чисто для примера
byt=fin.read() #Из базы данных изображении беру в таком виде
fin.close()

#Тут надо показать byt как картинку в editor (QTextEdit, QTextDocument,...)
#Можно любые средства использовать

sys.exit(app.exec_())

Any suggestions? Or is the only option to save the bytes as normal pictures?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jacob E, 2015-11-22
@c_pro_lang

Converting raw data into an image (and then rendering it without saving) is not a problem, you just have to look at the documentation - doc.qt.io/qt-4.8/qimage.html#QImage-4

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question