Reputation: 1369
In order to insert an image in a QTextDocument I have to modify its width and its height and to keep the original image's ratio. Hence my code :
qtextimageformat.setWidth( new_width );
cursor.insertImage( qtextimageformat, position )
I thought it was mandatory to modify the width and height but I was surprized to see that the call to .setWidth() somehow preserved the image's ratio, as if .setHeight() was implicitly called with the right parameter.
Is this the expected behaviour ? Or I am missing something ? The documentation didn't help me.
Upvotes: 0
Views: 349
Reputation: 367
This is expected behavior, even if it is not explicit in documentation. The static functions QSize getImageSize(QTextDocument *doc, const QTextImageFormat &format)
and QSize getPixmapSize(QTextDocument *doc, const QTextImageFormat &format)
in qtextimagehandler.cpp
automatically deduce the height if only width was specified in QTextImageFormat
(and the opposite too)
Upvotes: 2