Hello

Assume i have a QListWidget with 2 items an both have checkboxes.

Qt Code:
  1. //listWidget creation
  2. {
  3. QListWidgetItem* item1 = new QListWidgetItem (tr( "string1"));
  4. item1->setCheckState ( Qt::Checked );
  5. QListWidgetItem* item2 = new QListWidgetItem (tr( "string2 ));
  6. item2->setCheckState ( Qt::Unchecked );
  7. }
  8.  
  9. //and the below function must find if the selected index from the QListWidget is checked,and do something inside:
  10.  
  11. void function::check(const QModelIndex &index)
  12. {
  13. //what code should it be here???
  14. //if checked do thing1
  15. //if unchecked do thing2
  16. }
To copy to clipboard, switch view to plain text mode 

I have to do the same thing with a QTreeView:
here's an exampe of the tree implementation:

Qt Code:
  1. QStandardItemModel *model::createTree( )
  2. {
  3. while ( ( condition ) )
  4. {
  5. QModelIndex index = model->index ( 0, 0 );
  6. model->insertRow ( 0 );
  7. if (condition==contition2)
  8. {
  9. model->setData ( index, someString);
  10. model->setData ( index, Qt::Checked, Qt::CheckStateRole );
  11. }
  12. else
  13. {
  14. model->setData ( index, someString);
  15. model->setData ( index, Qt::Unchecked, Qt::CheckStateRole );
  16. }
  17.  
  18. }
  19. }
  20. //so i have a model with checked and unchecked checkboxes
  21. //the tree gets the model with setModel and the i have to create a function that checks is the index is checked/unchecked:
  22.  
  23. void function::check(const QModelIndex &index)//the tree's index this time
  24. {
  25. //what code should it be here???
  26. //if checked do thing1
  27. //if unchecked do thing2
  28. }
To copy to clipboard, switch view to plain text mode 



Could this be done the same way as the QListWidget or the implementation of the check function should be diffferent for those two occasions?

Thanks!