Results 1 to 8 of 8

Thread: listview item focusing

  1. #1
    Join Date
    May 2009
    Posts
    129

    Default listview item focusing

    Dear All


    How do set the focus for particular item in listview ,suppose if i have 100 items, and scroll bar also enabled..


    Thanks

    Yuvaraj R

  2. #2
    Join Date
    Apr 2007
    Location
    Sunny Darwin, NT Australia
    Posts
    186
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: listview item focusing

    use scrollTo ( const QModelIndex & index, ScrollHint hint = EnsureVisible )

  3. #3
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: listview item focusing

    Quote Originally Posted by vieraci View Post
    use scrollTo ( const QModelIndex & index, ScrollHint hint = EnsureVisible )
    This will only scroll to make sure that item is visible.
    But to set focus or select item. Need to call select.

    Qt Code:
    1. listView->selectionModel()->select(listModel->index(row,column), QItemSelectionModel::Select);
    To copy to clipboard, switch view to plain text mode 
    Play with
    Qt Code:
    1. QItemSelectionModel::SelectionFlags // The 2nd argument of select function
    To copy to clipboard, switch view to plain text mode 
    to achive your desired focus/selection effect on the item.

  4. #4
    Join Date
    May 2009
    Posts
    129

    Default Re: listview item focusing

    Sorry for asking again


    ui->listView->scrollTo(0,ScrollHint hint = EnsureVisible );

    it is giving error like un declared scrollHint, ok,

    How do i declare it... it is method of QAbstractitemView class..

    please help me


    Thanks

    Yuvaraj R

  5. #5
    Join Date
    Apr 2007
    Location
    Sunny Darwin, NT Australia
    Posts
    186
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: listview item focusing

    You don't need to use ScrollHint hint = EnsureVisible, it is a default parameter.
    This is enough:
    Qt Code:
    1. ui->listView->scrollTo(yourRowNumber);
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    May 2009
    Posts
    129

    Default Re: listview item focusing

    Thanks Yogesh

    same thing i want to scroll.. if my item is in lasr position,as per u , we set focused the item, but we don't we where it is ?

    So i want to scroll it

    vieraci

    No it is giving error, if i pass only row value.

    Thanks

    Yuvaraj R

  7. #7
    Join Date
    May 2009
    Posts
    129

    Default Re: listview item focusing

    Thanks vieraci & Yogesh

    It is working ,i did stupid mistake previouisly

    Thanks

    Yuvaraj R

  8. #8
    Join Date
    Apr 2007
    Location
    Sunny Darwin, NT Australia
    Posts
    186
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: listview item focusing

    Try this then:
    Qt Code:
    1. ui->listView->scrollTo(yourRowNumber, 0);
    To copy to clipboard, switch view to plain text mode 

    You may need to create an index for your row/column. Look at QAbstractItemModel::createIndex

    And Yes, Yogesh is correct. You also need to select it as well.
    Last edited by vieraci; 18th August 2009 at 07:13. Reason: updated contents

Similar Threads

  1. Set default Selected item in ListView (QSqlQueryModel)
    By jeffpogo in forum Qt Programming
    Replies: 0
    Last Post: 26th May 2009, 22:12
  2. getting clicked item from listview
    By addu in forum Qt Programming
    Replies: 6
    Last Post: 14th May 2009, 10:33
  3. View, Scene, Item and thread??
    By dungsivn in forum Qt Programming
    Replies: 5
    Last Post: 20th August 2008, 19:21
  4. Item Delegate Painting
    By stevey in forum Qt Programming
    Replies: 3
    Last Post: 9th May 2008, 07:37
  5. Replies: 1
    Last Post: 19th April 2007, 22:23

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.