2

I implemented layers in my painting application. Each layer has a thumbnail preview. I want the thumbnail of a layer to only show the items that belong to that layer. Right now I call scene->render() that renders all items to the thumbnail. How can I select only items that have a certain parent?

QSize size = QSize(scene_->width(), scene_->height());
QImage *thumbnail = new QImage(size, QImage::Format_ARGB32);
thumbnail->fill(Qt::transparent); // Start all pixels transparent
QPainter imagePainter(thumbnail);
imagePainter.setRenderHint(QPainter::Antialiasing);
scene_->render(&imagePainter);
imagePainter.end();

The code above renders all times of the scene, but this is not what I want.

user2366975
  • 4,350
  • 9
  • 47
  • 87

1 Answers1

0

How can I select only items that have a certain parent?

The code above renders all times of the scene, but this is not what I want.

Assuming that each layer has it's own ultimate parent (that's not the scene root), you can simply set layer root's visibility to the visibility of the layer it's representing. Child objects 'inherit' their parent's visibility status (docs):

If you hide a parent item, all its children will also be hidden. If you show a parent item, all children will be shown, unless they have been explicitly hidden (i.e., if you call setVisible(false) on a child, it will not be reshown even if its parent is hidden, and then shown again).

cmannett85
  • 21,725
  • 8
  • 76
  • 119
  • That's indeed how the layers work: one parent item acts as a layer's root item, like this part of the docs says. By hiding it, I hide the layer's items. Do you mean that I should hide all layers but the one I want to render? I assume that the user will notice this hiding-and-showing of the layers. But I'll give it a try. – user2366975 Mar 22 '15 at 20:14