0
votes

I am creating a QGraphicsView, which shows a QGraphicsScene.

I set the background of the scene to a QImage bitmap, with:

scene()->setBackgroundBrush(myQImage);

I would like this image to tile relative to an offset, as I can do with:

painter.drawTiledPixmap(this->rect(), QPixmap::fromImage(myQImage), bgOffset);

Is there a way to do this, or should I just ignore the background brush ability of QGraphicsScene, and do it with a painter? This loses me caching of what might be a large background, though, and would royally mess up the scrollbars, so I'd rather not.

[Edit, context: I have a what is essentially a sprite-based character-designer (or avatar designer). I want people to be able to display a tiling background of their choosing, but I cannot restrict the dimensions of the background, and the central tile of the background must be displayed at a user-defined offset relative to the sprite they are designing. This background can be anything from a simple grid background (for pixel alignment), to a screenshot of an ingame map (character must be alignable to stand in the center of their desired map square), to a picture of another character's avatar for them to compare to or align against in a pixel-perfect way, and so on...]

1
You can edit the image itself to emulate background offset. You need to resort rows and columns so that origin point is at (0, 0). You can do that by cutting image into 4 pieces and joining them together in a different order. - Pavel Strakhov
Good approach, though since it's user-provided graphics, with a user-provided offset (I've edited OP with context), I'd have to edit on-the-fly in memory, which would be kludgy... but feasible, and wouldn't break the scrollbars, at least. Plonk this in an answer and I'll accept it if no better approach turns up. - Dewi Morgan
Don't forget to write it up as an answer, or I can't mark it as accepted! - Dewi Morgan

1 Answers

1
votes

You can edit the image itself to emulate background offset. You need to resort rows and columns so that origin point is at (0, 0). You can do that by cutting image into 4 pieces and joining them together in a different order.