Results 1 to 4 of 4

Thread: setZValue of QGraphicsItemGroup

  1. #1
    Join Date
    Oct 2006
    Posts
    83
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default setZValue of QGraphicsItemGroup

    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.
    Qt Code:
    1. bool form::eventFilter(QObject *o, QEvent *e)
    2. {
    3. if (o == ui.view->viewport())
    4. {
    5. QPointF point = ui.view->mapToScene(ui.view->mapFromGlobal(QCursor::pos()));
    6. QGraphicsItem *tmp = ui.view->itemAt(point.x(), point.y());
    7. if (tmp != 0)
    8. tmp->setZValue(1000.0);
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 
    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!
    Last edited by forrestfsu; 6th November 2006 at 18:38.

  2. #2
    Join Date
    Oct 2006
    Posts
    83
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: setZValue of QGraphicsItemGroup

    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);

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: setZValue of QGraphicsItemGroup

    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.
    J-P Nurmi

  4. #4
    Join Date
    Oct 2006
    Posts
    83
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: setZValue of QGraphicsItemGroup

    Thanks JPN, I was checking to make sure
    Qt Code:
    1. if (e->type() ==QEvent::MouseButtonPress)
    To copy to clipboard, switch view to plain text mode 

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

Similar Threads

  1. setZValue with groupitem doesn't seem to work
    By forrestfsu in forum Qt Programming
    Replies: 1
    Last Post: 24th October 2006, 21:39
  2. Delete all members in a QGraphicsItemGroup
    By vmferreira in forum Qt Programming
    Replies: 3
    Last Post: 17th August 2006, 18:47

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.