views:

314

answers:

1

I have a QGraphicsScene where I initially drew the background in the drawBackground() function. However, this required quite a few calculations and turned out to be pretty slow so I created a bunch of items instead. This had the expected speedup.

My question: is there a way to treat these items as the background? Would it even matter if I treated them as background items?

Thanks

+1  A: 

There are three layers in terms of QGraphicsScene (see Qt docs):

  • QGraphicsScene::ItemLayer

The item layer. QGraphicsScene renders all items are in this layer by calling the virtual function drawItems(). The item layer is drawn after the background layer, but before the foreground layer.

  • QGraphicsScene::BackgroundLayer

The background layer. QGraphicsScene renders the scene's background in this layer by calling the virtual function drawBackground(). The background layer is drawn first of all layers.

  • QGraphicsScene::ForegroundLayer

The foreground layer. QGraphicsScene renders the scene's foreground in this layer by calling the virtual function drawForeground(). The foreground layer is drawn last of all layers.

Threrefore, there is no legal way to put an item into the background layer. However, you could use QGraphicsItem Sorting to place some items behind others, making them to appear as a background.

Anton
I guess I could still put the stuff in drawBackground() but cache all the calculated stuff as it is static. However, this results in two phases for the background which I don't like.Do you know if there are any drawbacks to using items instead? They're a bunch of text and rect items with some transparencies..
cheez
I think the best way is to use items. Don't know any drawback.
Anton
Alright, that sounds like the thing to do. Thanks.
cheez