1

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

Naruto
  • 9,476
  • 37
  • 118
  • 201

1 Answers1

3

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.

Christophe Weis
  • 2,518
  • 4
  • 28
  • 32
Patrice Bernassola
  • 14,136
  • 6
  • 46
  • 59
  • 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? – Naruto Mar 19 '10 at 09:08
  • 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 Mar 19 '10 at 09:57
  • 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 – Naruto Mar 19 '10 at 10:49
  • Use the setItem function: http://doc.trolltech.com/4.6/qstandarditemmodel.html#setItem – Patrice Bernassola Mar 19 '10 at 11:00