Results 1 to 2 of 2

Thread: Sorting objects with setZValue()

  1. #1
    Join Date
    Dec 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Sorting objects with setZValue()

    Hi
    I'm new to Qt (using Qt Creator 2.1.0 with Qt version 4.7.2) and have an issue with sorting objects in to the correct order. i.e. I want to understand how to correctly use setZValue() in order to do that.

    My app allows for insertion of three types of objects in to a work area.
    e.g.
    object 1: triangle
    object 2: rectangle
    object 3: circle

    What I want to happen is that whenever a new circle is inserted it should always go on top of all other objects (including existing circles) that are already in the work area.
    I give Z-values of 1,2 and 3 to triangle, rectangle and circle respectively.
    e.g.
    Qt Code:
    1. MyAppCircle *item = new MyAppCircle(this);
    2. item->setZValue(3)
    To copy to clipboard, switch view to plain text mode 
    Results of test run:
    1) add rectangle. OK
    2) add circle. it goes on top of rectangle. OK
    3) click on visible part of rectangle. rectangle comes in to foreground and circle moves back. OK
    4) add a new circle. it goes in the middle of the two existing object. i.e. behind rectangle and in front of the old circle. Not OK. As with a Z-value of 3 I expect it to go to the top of the stack.

    I hope I've managed to explain the issue clearly.
    Any help would be much appreciated.
    Last edited by IK; 14th May 2012 at 17:52. Reason: updated contents

  2. #2
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Sorting objects with setZValue()

    Aren't you changing the zValue of the rectangle to greater than 3 to bring it to the top of the stack? If that is the case, the added circle would be on top of the first circle but below the rectangle.

Similar Threads

  1. Sorting objects with setZValue()
    By IK in forum General Programming
    Replies: 0
    Last Post: 14th May 2012, 14:58
  2. QGraphicsItem and setZValue problem with overlapping
    By T4ng10r in forum Qt Programming
    Replies: 0
    Last Post: 7th December 2009, 14:04
  3. setZValue of QGraphicsItemGroup
    By forrestfsu in forum Qt Programming
    Replies: 3
    Last Post: 6th November 2006, 19:40
  4. setZValue with groupitem doesn't seem to work
    By forrestfsu in forum Qt Programming
    Replies: 1
    Last Post: 24th October 2006, 21:39
  5. Replies: 7
    Last Post: 18th July 2006, 21:33

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
  •  
Qt is a trademark of The Qt Company.