[Qt-interest] pixmap.scaled gives empty pixmap

Constantin Makshin cmakshin at gmail.com
Wed Jul 21 20:46:16 CEST 2010


QPainter::scale()'s parameters are scale factors for X and Y axes, i.e. values greater than 1 act as "zoom in" and values less than 1 act as "zoom out". So values passed to this function are rather small (unless you want extreme zooming).

QPixmap::scaled() takes dimensions the image must be scaled to, i.e. width and height of the new image. So values passed to this function are (in most cases) significantly greater than parameters of QPainter::scale().

I suspect that's the problem — your 'scaleFrac*' values cause the image to be very small or even not visible at all (if either of the variables is less than 0.5, it's value will be rounded to zero and that'll "destroy" your image).

On Wednesday 21 July 2010 12:56:20 Matthias Pospiech wrote:
> If I change in the following code the painter scale to the 
> pixmap.scaled, the I get no output in my widget.
> 
> void QCameraImageBase::paintEvent(QPaintEvent * event)
> {
>     QPainter painter(this);
>     painter.scale(scaleFracX, scaleFracY);
>     //d->pixmap = d->pixmap.scaled(scaleFracX, scaleFracY, d->aspectRatio);
>     painter.drawPixmap(0, 0, d->pixmap);
> }
> 
> Why? I am interested in pixmap.scaled only because of the possibility to 
> keep the aspect ratio, which I otherwise would have to programm on my own.
> 
> Matthias



More information about the Qt-interest-old mailing list