Reputation: 37
I am trying to make a program in Qt/C++ which makes basic Class Diagrams from C++ code. To show output, I chose to print the diagrams on a QImage using QPainter. However, I have no way of knowing how much space (width * height) will be required for the provided code. I tried to first draw image on a 5000x5000 QImage and then 'scale' it to the required dimensions but after the scaling, text(which is also Drawn using QPainter::drawText) on the QImage becomes impossible to read. Is there a way to either EXPAND QImage as needed or if not possible kindly suggest some other workaround.
I am pretty new to Qt so kindly be as elaborate as possible.
RELEVANT CODE PIECES:
QImage temp_img(5000,5000, QImage::Format_ARGB32);
QImage final_img = temp_img.scaled(800, l_y+30,Qt::KeepAspectRatio);
l_y is the end height of the printed diagram.
Upvotes: 0
Views: 1048
Reputation: 62797
What you want to do is not scaling image, that is changing the pixels (scaling down by combining several pixels, or scaling up by adding pixels). What you want to do is just remove parts of image, also known as cropping the image. Or to say it the other way, you want to copy part of the image, leaving unneeded parts behind.
You can achieve this using QImage::copy
method.
As a side note, since your image is really a line drawing (I assume), consider using a vector image format, so viewer can scale the image freely. Qt has QSvgGenerator
class which can do this.
Upvotes: 1