PDA

View Full Version : setZValue with groupitem doesn't seem to work



forrestfsu
24th October 2006, 21:25
I am trying to create a QGraphicsEllipseItem that is shown stacked on top of all other elements (because it is the newest one created). I don't understand why the following is not working by using the "setZValue" function. Is there a way to just make it go on top of all other scene elements because it's the newest? Thanks!



QGraphicsItemGroup *group;
group = new QGraphicsItemGroup();

QGraphicsEllipseItem *tmp;
tmp = scene->addEllipse(QRectF(x, y, 10, 10));
tmp->setPen(pen);
tmp->setBrush(brush);
tmp->setZValue(1000.0);
group->addToGroup(tmp);


I noticed that when I comment out the last line "group->addToGroup(tmp);" the setZValue seems to work. Any input would be super.

forrestfsu
24th October 2006, 21:39
I can't believe this is all I had to do to solve the issue! I can't even explain how much time I wasted looking at this, but here's the correct way to do it:



QGraphicsItemGroup *group;
group = new QGraphicsItemGroup();
QGraphicsEllipseItem *tmp;
tmp = scene->addEllipse(QRectF(x, y, 10, 10));
tmp->setPen(pen);
tmp->setBrush(brush);
group->addToGroup(tmp);
group->setZValue(1000.0);