Results 1 to 3 of 3

Thread: Order of elemetns with QGraphicsScene::itemAt

  1. #1
    Join Date
    Feb 2006
    Posts
    209
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Order of elemetns with QGraphicsScene::itemAt

    Hi.
    If there are several items at a point, the item that will be returned with the QGraphicsScene::itemAt function will be the one with the highest zValue, right?
    But what if there is two QGraphicsItems, call them A and B where A is parent to B and B has lower zValue, which one will be returned?

    In this situation I would really like B to be returned, if itemAt does not do this, how do you do it then?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Order of elemetns with QGraphicsScene::itemAt

    You could try to use item( const QPointF & ) method to get all items at that position and then something like this:
    Qt Code:
    1. QGraphicsItem *item = items.first();
    2. foreach( QGraphicsItem *tmpItem, items ) {
    3. if( tmpItem->parentItem() == item ) {
    4. item = tmpItem;
    5. }
    6. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Norway
    Posts
    124
    Thanked 38 Times in 30 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Order of elemetns with QGraphicsScene::itemAt

    See the docs for QGraphicsItem::zValue(), it's explained in detail there. Children are always on top of parents, and because of this, children are always listed before parents in the itemAt() and items() functions.

    http://doc.trolltech.com/4.2/qgraphi...html#setZValue
    Bitto / Andreas Aardal Hanssen - andreas dot aardal dot hanssen at nokia
    Nokia Software Manager, Qt Development

Similar Threads

  1. Tab Order Settings in a QDialog widgets
    By vinnu in forum Qt Programming
    Replies: 10
    Last Post: 21st September 2006, 16:25
  2. about QHash elements order
    By bruce1007 in forum Qt Programming
    Replies: 2
    Last Post: 25th August 2006, 07:17
  3. Replies: 1
    Last Post: 26th February 2006, 05:52
  4. Changing the order of columns in QTreeView
    By johnny_sparx in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2006, 00:00

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.