View Full Version : listview item focusing
addu
18th August 2009, 05:51
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
vieraci
18th August 2009, 06:16
use scrollTo ( const QModelIndex & index, ScrollHint hint = EnsureVisible )
yogeshgokul
18th August 2009, 06:34
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.
listView->selectionModel()->select(listModel->index(row,column), QItemSelectionModel::Select);
Play with
QItemSelectionModel::SelectionFlags // The 2nd argument of select function to achive your desired focus/selection effect on the item.
addu
18th August 2009, 06:45
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
vieraci
18th August 2009, 06:51
You don't need to use ScrollHint hint = EnsureVisible, it is a default parameter.
This is enough:
ui->listView->scrollTo(yourRowNumber);
addu
18th August 2009, 06:55
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
addu
18th August 2009, 07:04
Thanks vieraci & Yogesh
It is working ,i did stupid mistake previouisly
Thanks
Yuvaraj R
vieraci
18th August 2009, 07:07
Try this then:
ui->listView->scrollTo(yourRowNumber, 0);
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.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.