views:

39

answers:

1

Hi.. Can any one tell me how to set the item to be selected forcefully..

I tried this after adding items to list row..

QModelIndex index = mylistview->currentIndex();
             mylistview ->setCurrentIndex(index);

its not working.. index I am getting index (-1,-1).. can any one help me on this

Thanks

+2  A: 

Have you check the you have authorized selection? In the Qt Documentation, it is explain the item is selected unless selection mode is No Selection.

Patrice Bernassola
i got solution below code works well.. i have one more problem with this, QModelIndex index = mylistmodel->index(row,0); mylistview->setCurrentIndex(index);i.e in my app, I am doing appendrow() to insert elements to listview,when the rowsInserted signal is triggered, I am getting column numbers like 0,1,2,3 etc..I want only one column i.e(0th column) only…Appendrow() doesn’t put elements to the next row or wat?
Shadow
AppendRow can append one or more item to your model. In the insertRows slot you will receive the range of inserted rows. If you have append only one row, start and end will have the same value
Patrice Bernassola
ok.. i got it.. but how can i modify the same..shall i use insertrows()?and i have to mention the row name explicitly or it takes by default?which one do you suggest.Thanks
Shadow
Use the setItem function: http://doc.trolltech.com/4.6/qstandarditemmodel.html#setItem
Patrice Bernassola
Thanks.. ill use as you suggested
Shadow