how to add check box inside qtree widget?
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
Code:
#include "dialog.h"
#include "ui_dialog.h"
#include <QtCore>
#include <QtGui>
ui(new Ui::Dialog)
{
ui->setupUi(this);
ui->treeWidget->setColumnCount(2);
ui
->treeWidget
->setHeaderLabels
(QStringList()<<
"one"<<
"two");
AddRoot("1 first","tree");
AddRoot("2 second","person");
AddRoot("3 third","man");
AddRoot("4 fourth","and last");
}
Dialog::~Dialog()
{
delete ui;
}
{
itm->setText(0,name);
itm->setText(1,Description);
AddChild(itm,"one","1111");
AddChild(itm,"two","2222");
}
{
itm->setText(0,name);
itm->setText(1,Description);
parent->addChild(itm);
}
void Dialog::on_pushButton_clicked()
{
ui->treeWidget->currentItem()->setBackgroundColor(0,Qt::red);
ui->treeWidget->currentItem()->setBackgroundColor(1,Qt::blue);
}
here i need check box to select - "one" ,"111"
and "two","2222222"...
please tell me how can i do that?
Re: how to add check box inside qtree widget?
Hello.
In QTableWidget I used
setFlags ( Qt::ItemFlags flags )
and add flags Qt::ItemIsUserCheckable.
Try in your case.
The QTreeWidget has the same features.
Re: how to add check box inside qtree widget?
Re: how to add check box inside qtree widget?
@kunashir
Can you mention the code excerpt which you used for ItemFlags usage?
Thanks in advance!!
Re: how to add check box inside qtree widget?
You already have the name of the function, QTreeWidgetItem::setFlags(), its documentation, and the Qt::ItemFlag documentation it links to. You even have the the name of the specific flag, Qt::ItemIsUserCheckable. Is it really such a difficult thing to work out?
Code:
// OR QTableWidgetItem *item = new QTableWidgetItem();
// OR QStandardItem *item = new QStandardItem();
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsUserCheckable);