PDA

View Full Version : Pixmap in QGraphicsScene disappears when it is scaled above 32,767 pixels



HereWeAre
31st October 2015, 16:53
I have a QGraphicsScene in a QGraphicsView that displays a scaled pixmap. For some reason, when the pixmap is larger than 32,767 pixels (max value of type int), it fails to show up at all or sometimes partially shows up.

The QGraphicsView documentation for QT5 says:

Note that although the scene supports a virtually unlimited size, the range of the scroll bars will never exceed the range of an integer (INT_MIN, INT_MAX).


However, I should be able to display a pixmap larger than 32,767 pixels because I printed INT_MIN and INT_MAX and they are INT_MIN = -2147483648, INT_MAX = 2147483647 on my system (I'm running an Intel processor on Ubuntu 14.04). What could cause the pixmap to not show up when it gets larger than 32,767 pixels in one dimension? As long as it's below 32,767 pixels, the image displays properly. Is this a bug in Qt? Code below.


// Transformation matrix
QMatrix matrix;
if(!time_vertical) {
matrix.scale(1, -1);
matrix.rotate(90);
}
matrix.scale(frequency_zoom, time_zoom);
// Create pixmap
pixmap.convertFromImage(*image);
pixmap = pixmap.transformed(matrix);
// Add pixmap to scene
scene->clear();
QGraphicsPixmapItem* item = scene->addPixmap(pixmap);
item->setPos(0, 0); // Set pixmap origin (0, 0) in scene coordinates
scene->setSceneRect(pixmap.rect());

anda_skoa
1st November 2015, 10:18
I think this is a limitation in X11.

If I remember correctly its size arguments are 16-bit ints, so the maximum value is 32727.

If your screen is smaller than this size then you could try scaling the image and then taking the visible part into a pixmap, or using a custom item that draws only the visible part of the scaled image or draws the visible part using painter scaling.

If your screen is that size or larger, then you probably need a custom item that draws the scaled image in tiles.
In that case I would also ask to attach a photo of that video wall :)

Cheers,
_

HereWeAre
2nd November 2015, 16:28
Hmm, X11? I guess I could verify by compiling and running it in Windows. That's true, I could re-draw every time the user scrolls, but that might add some lag.

I should be able to shift the scene rectangle so it starts at -32767 instead of 0 and effectively double the largest possible size, but I haven't been able to get that to work. The QGraphics scene rectangle still starts at (0,0). Not sure why.

anda_skoa
2nd November 2015, 18:00
Hmm, X11?

You wrote Ubuntu, version from last year, so unlikely that you are using Mir as the display server.
But of course you could be running without X11, maybe a framebuffer or EGLFS?
Is this a desktop or an embedded system?



I guess I could verify by compiling and running it in Windows. That's true, I could re-draw every time the user scrolls, but that might add some lag.

The graphics view has to redraw anyway.



I should be able to shift the scene rectangle so it starts at -32767 instead of 0 and effectively double the largest possible size, but I haven't been able to get that to work. The QGraphics scene rectangle still starts at (0,0). Not sure why.
That won't help if you are on X11.
As I wrote it uses 16 bit ints for sizes, so an X11 Pixmap (and thus a QPixmap wrapping it) can't be larger than 32767.
Even at that size in both directions it would already consume 4GB.

Cheers,
_

HereWeAre
2nd November 2015, 21:59
I am definitely using X11. The Hmm was just a little surprise that the problem was there. I'll try out your suggestion. This has been very helpful, thank you!