PDA

View Full Version : setZValue of QGraphicsItemGroup



forrestfsu
6th November 2006, 19:33
I have a scene with a mosaic of QGraphicItemGroup's and I'm trying to make it when the user clicks on one of the QGraphicsItemGroup's it will bring it to the front. I have tried a few modifications of the following code snippit with no success.


bool form::eventFilter(QObject *o, QEvent *e)
{
if (o == ui.view->viewport())
{
QPointF point = ui.view->mapToScene(ui.view->mapFromGlobal(QCursor::pos()));
QGraphicsItem *tmp = ui.view->itemAt(point.x(), point.y());
if (tmp != 0)
tmp->setZValue(1000.0);
}
}

Am I not supposed to be using the QGraphicsView's eventFilter for this?
When I use the itemAt function it returns a QGraphicsItem. Does it need to be a QGraphicsItemGroup?

Any tips would be great...

Note: I posted a similar question a while back, but I don't see this as the same question. In my previous post I was able to add an object to a new QGraphicsItemGroup prior to setting the ZValue. In this case, I already have the group's created, and I just want to display a certain one above others.

Thanks!

forrestfsu
6th November 2006, 20:07
This seems to work:

tmp->parentItem()->setZValue(1000.0);

However, I need to keep a counter to maintain which zvalue is at the top. So this would be the final solution:

tmp->parentItem()->setZValue(++counter);

jpn
6th November 2006, 20:12
You might want to check the event type in the event filter.. I doubt you really want to set the Z value upon every single event the view receives.

forrestfsu
6th November 2006, 20:40
Thanks JPN, I was checking to make sure


if (e->type() ==QEvent::MouseButtonPress)


I just left it out to help simplify my problem for the reader. Good eye though :)