PDA

View Full Version : QPixmap not displayed on windows / no proble on Linx -> Qt Bug or not?



ali99
5th April 2006, 13:02
Hi,
I am displaying images in a scrollview. I also have scaling functionality that works without problems on linux. When I do the same on windows the image won't be displayed when the size exceeds approximately 3000x30000 pixels. Is there a problem with Qt or am I doing something wrong?


//
//this code is inside a class that subclasses QScrollView
//
QVBox *box = new QVBox(viewport());
addChild(box);

...

imgLabel_ = new QLabel(box);
isOk = pixMapScaled_.convertFromImage(
image_.scale(static_cast<int>(image_.width()*scaleFactor_),
static_cast<int>(image_.height()*scaleFactor_)),
conversion_flags_);

if (isOk)
imgLabel_->setPixmap(pixMapScaled_);
else
logger_.error("Could not convert image.");


The scaling and conversion seems to happen without any errors. The image is just not displayed on windows when it gets bigger than 3000x3000 pixels. When scaling out again it will be displayed again.
Thanks, for any help,
Guido

dimitri
9th April 2006, 11:55
Can you provide a minimal compilable example that reproduces the problem?

My guess is that you're trying to create very large pixmaps (larger than the screen) which isn't needed and may fail on some systems. It's hard to help more without details.

A QImage an be any size you want (provided there's enough system memory) but a QPixmap is specifically used to display, so it doesn't make sense to have a pixmap larger than the screen typically.

ali99
10th April 2006, 08:15
why should it not make sense to have a pixmap that is bigger than the screen? When you scale a high resolution image in order to zoom into the image it will become very quick bigger than the screen. In my case (1280x1024) it was working until 2700x2700 pixels. When I reached 3000x3000 it stopped displaying it. My application needs to be able to zoom into images. And it all works on linux without problems.
Thanks so much for your help,
Guido

wysota
10th April 2006, 09:32
The proper question is -- does your application need to use QPixmap for this? And a second question -- does the image need to be that big to be shown zoomed?

ali99
10th April 2006, 10:09
To use QPixmap is the only way I know to do what I want to do. That is showing an image in a QScrollView. When the image is zoomed in you can scroll that image to any position wanted. I am not an expert with using Qt, rather an intermediate. And doing that QImage->QPixmap->QLabel - "trick" looked strange to me but that is what I was told to do in order to get the wanted results.
Guido

wysota
10th April 2006, 10:38
How about using QPainter::drawImage() instead? And QPainter::scale() for zooming?

If you have a 300x300 pixel image which occupies about 100kB of memory and you zoom it 4 times (making it 1200x1200) you'll use 1.5MB of memory... with 3000x3000 it'll be 9MB, etc. If you use QPainter::scale and QPainter::drawImage, you'll be at 100kB memory usage all the time.

dimitri
10th April 2006, 10:47
A QImage lives in your system's main memory and can therefore be quite large.

A QPixmap is handled by the graphics subsystem of your computer and there are limitations on the size of pixmaps that can be handled. This is not a Qt issue.

What you want is to load an image into a QImage (or some other custom specialized structure) in main memory. Then you extract/transform/zoom whatever part of the QImage you need to display, transforming it into a QPixmap and always trying to keep the pixmap a reasonable size. Again, this limitation is not related to Qt.

Now, instead of programming all that by yourself, you could reuse code from existing Qt or KDE high-level widgets that display images and can handle rotations, zooming, shearing, etc.

I don't have links to such programs right now, except maybe GRASS/Qt (http://navicon.dk/web/normal.php?pageid=92), but you'll probably be interested in A Zoomable Picture Viewer (http://qt4.digitalfanatics.org/articles/zoomer.html).