Results 1 to 2 of 2

Thread: QGraphicsScene sorting selected items

  1. #1
    Join Date
    Feb 2007
    Location
    Italy
    Posts
    69
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QGraphicsScene sorting selected items

    Hello,
    from documentation

    QList<QGraphicsItem *> QGraphicsScene::selectedItems () const
    Returns a list of all currently selected items. The items are returned in no particular order.
    but I need to track the selection order if user selects items individually (or any order if uses rubber band). What shall I change to achieve this behavior?
    I was thinking to reimplement mousePressEvent() and track of clicked items, but since QGraphicsScene already handles selections, I prefer to do as less damage as possible to the current behavior

    Any help is welcome
    Thanks in advance
    ~Aki

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsScene sorting selected items

    Make user of QGraphicsItems.itemChange(QGraphicsItem::ItemSelec tedHasChanged); this gets called when, for instance, the selection state changes. You can then call a static function that provides incrementing values each time it is called to set internally. Finally, you can sort your items on this value.

    There are a few wrinkles involved, like keeping track of items being selected multiple times, or unselected, but nothing terribly complicated.

  3. The following 2 users say thank you to SixDegrees for this useful post:

    akiross (3rd April 2011), JohannesMunk (2nd April 2011)

Similar Threads

  1. QGraphicsScene sorting takes a lot of time
    By f-r-o-s-t in forum Qt Programming
    Replies: 6
    Last Post: 23rd May 2010, 16:24
  2. Replies: 1
    Last Post: 7th May 2010, 15:01
  3. Sorting Combobox Items
    By raphaelf in forum Newbie
    Replies: 5
    Last Post: 23rd June 2008, 08:00
  4. Getting indexes of selected items
    By gyre in forum Newbie
    Replies: 2
    Last Post: 20th November 2007, 19:23
  5. Sorting Tree items based on database properties
    By jnk5y in forum Qt Programming
    Replies: 3
    Last Post: 13th April 2006, 19:44

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.