[Qt-interest] QPainter, image scaling problem

Hannu Shemeikka hps at shemeikka.org
Sun Oct 10 12:05:53 CEST 2010


Hi,

I need to implement a zoom in & zoom out function in my application.
Currently the image is displayed in custom QGLWidget which is inserted
into vertical layout.

Normal situation is displayed in attached image_normal.png. I use
QPainter to draw QImage. The size is 700x700. 

paintEvent-code:
*****************
QPainter painter2(this);
QRectF target(0.0, 0.0, ROWS, COLUMNS); // 700,700
painter2.setWindow(0,0,ROWS,COLUMNS);   // 700,700

painter2.scale(this->dScaleFactor ,this->dScaleFactor);
painter2.drawImage(target,*this->grayImage);
*****************

dScaleFactor is increased by 0.1 every time left mouse button is clicked
and decreased by 0.1 every right button click.


The Problem:

Every time scaling is used, it moves the image a bit further to right,
outside the view. Attached image_scaled.png show the image position
after 6 clicks.

The Question:

Is there a way to move the image to left so that the gray stuff
displayed in both images would stay in center of the view when clicking
the left mouse button (using the scale-function) ?

Or is there a completely another way to do zoom in & zoom out on
QPainter?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: image_normal.png
Type: image/png
Size: 62311 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101010/af822575/attachment.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image_scaled.png
Type: image/png
Size: 38186 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101010/af822575/attachment-0001.png 


More information about the Qt-interest-old mailing list