Hi all,
In my project i'm using a tree widget.
Which i created using designer...
Now i wanted to add checkbox at each child..
How can i do that?
My code to create the tree widget as shown below
Qt Code:
  1. #include "dialog.h"
  2. #include "ui_dialog.h"
  3. #include <QtCore>
  4. #include <QtGui>
  5.  
  6. Dialog::Dialog(QWidget *parent) :
  7. QDialog(parent),
  8. ui(new Ui::Dialog)
  9. {
  10.  
  11. ui->setupUi(this);
  12.  
  13. ui->treeWidget->setColumnCount(2);
  14. ui->treeWidget->setHeaderLabels(QStringList()<< "one"<<"two");
  15. AddRoot("1 first","tree");
  16. AddRoot("2 second","person");
  17. AddRoot("3 third","man");
  18. AddRoot("4 fourth","and last");
  19.  
  20. }
  21.  
  22. Dialog::~Dialog()
  23. {
  24. delete ui;
  25. }
  26. void Dialog::AddRoot(QString name,QString Description)
  27. {
  28. QTreeWidgetItem *itm =new QTreeWidgetItem(ui->treeWidget);
  29. itm->setText(0,name);
  30. itm->setText(1,Description);
  31.  
  32.  
  33. AddChild(itm,"one","1111");
  34. AddChild(itm,"two","2222");
  35. }
  36.  
  37. void Dialog::AddChild(QTreeWidgetItem *parent,QString name, QString Description)
  38. {
  39. itm->setText(0,name);
  40. itm->setText(1,Description);
  41. parent->addChild(itm);
  42. }
  43.  
  44. void Dialog::on_pushButton_clicked()
  45. {
  46. ui->treeWidget->currentItem()->setBackgroundColor(0,Qt::red);
  47.  
  48. ui->treeWidget->currentItem()->setBackgroundColor(1,Qt::blue);
  49. }
To copy to clipboard, switch view to plain text mode 



here i need check box to select - "one" ,"111"
and "two","2222222"...
please tell me how can i do that?