[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: unable to add image to QTextDocument saved as .odt file
From: Roberta Fagandini <robifagandini () gmail ! com>
Date: 2022-08-16 12:08:29
Message-ID: CAFFLmWLMfwc_vRh0=kU847xcBkQLZv3OggUHn2Nc-XoYwmaakw () mail ! gmail ! com
[Download RAW message or body]
Hi all,
I have developed a QGIS python plugin whose output is an .odt file with
text and images. In order to create the .odt file I have written the
folowing code block:
'''
*html_text = '<!DOCTYPE html><html><head></head><body>\*
*<p>My text</p>\*
*<p style="text-align:center; vertical-align: middle;">\*
*<img src="path/to/image/logo.png"></p>\</body></html>'*
*doc = QTextDocument()doc.setHtml( html_text )*
*writer =
QTextDocumentWriter()writer.setFormat(QByteArray(b'ODF'))writer.setFileName('path/to/file/test.odt')writer.write(doc)*
'''
The code above works perfectly till QGIS 3.16 version wich was compiled
with Qt 5.11. In the later QGIS versions (3.22 - 3.24 - 3.26) compiled with
Qt 5.15, the odt file is correctly created but the image is not added to
the file. If I change the file format, for instance
*writer.setFormat(QByteArray(b'HTML'))*, the image is added to the created
html file also with Qt 5.15.
I have the same problem using QTextCursor.insertImage():
'''
*doc = QtGui.QTextDocument()cursor =
QtGui.QTextCursor(doc)cursor.insertText('Hello
world')cursor.insertImage('path/to/image/logo.png')writer =
QtGui.QTextDocumentWriter()writer.setFormat( QByteArray(b'ODF')
)writer.setFileName(' path/to/file /test.odt')*
'''
The image is correctly added to the odt file with Qt 5.11 while it is not
added to the odt file with Qt 5.15.
Is this a bug or somenthing change in the QTextDocument
and QTextDocumentWriter classes? Looking at the documentation the html img
tag is still supported by the setHtml function (
https://doc.qt.io/qt-5/richtext-html-subset.html).
Any idea?
Thanks in advance!!
Roberta
--
*Arch. Roberta Fagandini, PhD*
*GIS and Remote Sensing Technician*
*Gter srl (Unige spin-off)*
*Via Jacopo Ruffini 9/1A - 16128 Genova*
*P.IVA/CF 01998770992*
*www.gter.it* <http://www.gter.it/>
*--*
*Gter social*
*www.twitter.com/Gteronline* <http://www.twitter.com/Gteronline>* - *
*www.facebook.com/Gteronline* <http://www.facebook.com/Gteronline>* -*
*www.linkedin.com/company/gter-srl-innovazione-in-geomatica-gnss-e-gis
<http://www.linkedin.com/company/gter-srl-innovazione-in-geomatica-gnss-e-gis>*
[Attachment #3 (text/html)]
<div dir="ltr">Hi all,<div>I have developed a QGIS python plugin whose output is an \
.odt file with text and images. In order to create the .odt file I have written the \
folowing code block:</div><div>'''</div><div><i>html_text = \
'<!DOCTYPE html><html><head></head><body>\</i></div><div><div><i><p>My \
text</p>\</i></div><i><p style="text-align:center; vertical-align: \
middle;">\</i></div><div><i><img \
src="path/to/image/logo.png"></p>\<br></body></html>'</i></div><div><i><br>doc \
= QTextDocument()<br>doc.setHtml( html_text )</i></div><div><i><br>writer = \
QTextDocumentWriter()<br>writer.setFormat(QByteArray(b'ODF'))<br>writer.setFil \
eName('path/to/file/test.odt')<br>writer.write(doc)</i></div><div><br></div><div>'''</div><div>The \
code above works perfectly till QGIS 3.16 version wich was compiled with Qt 5.11. \
In the later QGIS versions (3.22 - 3.24 - 3.26) compiled with Qt 5.15, the odt file \
is correctly created but the image is not added to the file. If I change the file \
format, for instance <i>writer.setFormat(QByteArray(b'HTML'))</i>, the \
image is added to the created html file also with Qt 5.15. </div><div>I have the \
same problem using QTextCursor.insertImage():</div><div>'''</div><div><i>doc \
= QtGui.QTextDocument()<br>cursor = \
QtGui.QTextCursor(doc)<br><br>cursor.insertText('Hello \
world')<br>cursor.insertImage('path/to/image/logo.png')<br><br>writer = \
QtGui.QTextDocumentWriter()<br>writer.setFormat( QByteArray(b'ODF') \
)<br>writer.setFileName(' path/to/file \
/test.odt')</i><br></div><div>'''</div><div>The image is correctly \
added to the odt file with Qt 5.11 while it is not added to the odt file with Qt \
5.15.<br clear="all"><div><br></div><div>Is this a bug or somenthing change in the \
QTextDocument and QTextDocumentWriter classes? Looking at the documentation the html \
img tag is still supported by the setHtml function (<a \
href="https://doc.qt.io/qt-5/richtext-html-subset.html" \
target="_blank">https://doc.qt.io/qt-5/richtext-html-subset.html</a>).</div><div><br></div><div>Any \
idea?</div><div><br></div><div>Thanks in \
advance!!</div><div>Roberta</div></div><div><br></div>-- <br><div dir="ltr" \
class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div \
dir="ltr"><div style="color:rgb(0,0,0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:13.3333px"><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)"></span></span><i><span style="font-size:10px"><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)">Arch. Roberta Fagandini, \
PhD</span></span></span></i><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)"></span></span><br></div><div \
style="color:rgb(0,0,0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:13.3333px"><i><span \
style="font-size:10px"><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)">GIS and Remote Sensing \
Technician</span></span></span></i><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)"></span></span><br></div><div \
style="color:rgb(0,0,0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:13.3333px"><i><span \
style="font-size:10px"><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)">Gter srl (Unige \
spin-off)</span></span></span></i><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)"></span></span><br></div><div \
style="color:rgb(0,0,0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:13.3333px"><i \
style="font-size:13.3333px"><span style="font-size:10px"><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)">Via Jacopo Ruffini 9/1A - 16128 \
Genova</span></span></span></i><br></div><div \
style="color:rgb(0,0,0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:13.3333px"><i><span \
style="font-size:10px"><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)">P.IVA/CF \
01998770992</span></span></span></i></div><div \
style="color:rgb(0,0,0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:13.3333px"><a \
href="http://www.gter.it/" style="color:rgb(89,143,222)" target="_blank"><i><span \
style="font-size:10px"><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)">www.gter.it</span></span></span></i></a><i><span \
style="font-size:10px"></span></i><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)"></span></span><i><span \
style="font-size:10px"></span></i><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)"></span></span><br></div><div \
style="color:rgb(0,0,0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:13.3333px"><i><span \
style="font-size:10px"><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)">--</span></span></span></i><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)"></span></span><br></div><div \
style="color:rgb(0,0,0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:13.3333px"><i><span \
style="font-size:10px"><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)">Gter social</span></span></span></i><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)"></span></span><br></div><div \
style="color:rgb(0,0,0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:13.3333px"><a \
href="http://www.twitter.com/Gteronline" style="color:rgb(89,143,222)" \
target="_blank"><i><span style="font-size:10px"><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)">www.twitter.com/Gteronline</span></span></span></i></a><i><span \
style="font-size:10px"><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)"> - </span></span></span></i><a \
href="http://www.facebook.com/Gteronline" style="color:rgb(89,143,222)" \
target="_blank"><i><span style="font-size:10px"><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)">www.facebook.com/Gteronline</span></span></span></i></a><i><span \
style="font-size:10px"><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)"> -</span></span></span></i><br></div><div \
style="color:rgb(0,0,0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:13.3333px"><i><span \
style="color:rgb(89,143,222);font-size:10px"><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><span \
style="color:rgb(102,102,102)"><a \
href="http://www.linkedin.com/company/gter-srl-innovazione-in-geomatica-gnss-e-gis" \
style="color:rgb(89,143,222)" \
target="_blank">www.linkedin.com/company/gter-srl-innovazione-in-geomatica-gnss-e-gis</a></span></span></span></i><br></div><div><i><span \
style="color:rgb(89,143,222);font-size:10px"><span \
style="font-family:tahoma,arial,helvetica,sans-serif,sans-serif"><br></span></span></i></div></div></div></div></div>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic