Results 1 to 3 of 3

Thread: changing state of previously selected list item

  1. #1
    Join Date
    Mar 2011
    Posts
    5
    Qt products
    Qt4
    Platforms
    Symbian S60 Maemo/MeeGo

    Default changing state of previously selected list item

    Hi

    I have a QML application with ListView and ListModel. When I click an list item I'll change it's state (to "selected") and draw it bit differently. This works just fine.

    Next I'll select another item from the list. At this point I would like to change previously selected items state back to "unselected". I know the index of the item, but I can't figure out how to access delegate's state.

    How I can do this or is there better approach? I'm just testing and learning how to do things before actually implementing my application.

  2. #2
    Join Date
    May 2010
    Posts
    61
    Thanks
    2
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: changing state of previously selected list item

    Hi tyrnikeisari,

    You can try to access the attached property "view" of the QML ListView element from your delegate ListView.view.

    So in your delegate, when drawing the "selected" item you can use a condition like:
    Qt Code:
    1. if (ListView.view.currentIndex == index)
    To copy to clipboard, switch view to plain text mode 

    Hope this is useful.

    Regards,
    Wladek
    One second is long, everything longer than two seconds is definitely too long.

  3. #3
    Join Date
    Mar 2011
    Posts
    5
    Qt products
    Qt4
    Platforms
    Symbian S60 Maemo/MeeGo

    Default Re: changing state of previously selected list item

    Hi Wladek

    Thanks for your reply.

    I added the check when focus changes and that did the trick. I have in my delegate item:
    Qt Code:
    1. onFocusChanged: {
    2. if(listView.currentIndex == index){
    3. delegateItem.state = 'selected';
    4. }
    5. else{
    6. delegateItem.state = 'deselected';
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 


    br,
    Tyrnikeisari

Similar Threads

  1. Changing selected QTreeView item font
    By dima1000 in forum Newbie
    Replies: 5
    Last Post: 8th October 2009, 09:28
  2. err:"Unable to restore previously selected frame"
    By BalaQT in forum Qt Programming
    Replies: 1
    Last Post: 19th September 2009, 12:18
  3. Problem with item selected in a list
    By 0xl33t in forum Qt Programming
    Replies: 2
    Last Post: 3rd August 2009, 17:07
  4. Replies: 5
    Last Post: 19th April 2009, 13:24
  5. Changing selected item color in non-current window.
    By Doug Broadwell in forum Qt Programming
    Replies: 1
    Last Post: 26th August 2007, 07:09

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.