PDA

View Full Version : CheckBox in treeview



ansar
14th December 2009, 14:53
HI all,

I just want to insert the QcheckBoxes in Qtreeview.How can I do this.

i.e In treeview first should display the checkbox and other columns disppay the text in all rows.

Please help me out ...

:confused:

faldzip
14th December 2009, 15:14
if you are using QStandardItemModel then use QStandardItem::setCheckable() on item you want to be checkable. Checkstate of these items you can check with QStandardItem::checkState().

If you have your own QAbstractItemModel implementation then reimplement QAbstractItemModel::flags() method and return Qt::ItemIsUserCheckable for indexes that you want to be checkable. Checkstate is stored under Qt::CheckStateRole.

ansar
16th December 2009, 06:41
This is how I am doing currently... But instead of checkbox its displaing the combobox with true and false value .Where I am wrong exactly ? .....

:confused:



void addModel(QAbstractItemModel *model, const QCheckBox *check,const QString &name,
const QString &id, const QString &status )
{
model->insertRow(0);

model->setData(model->index(0, 0), check);
model->setData(model->index(0, 1), name);
model->setData(model->index(0, 2), id);
model->setData(model->index(0, 3), status);
}

QAbstractItemModel *createMailModel(QObject *parent)
{
QStandardItemModel *model = new QStandardItemModel(0, 4, parent);
QCheckBox *check = new QCheckBox("");


model->isWidgetType();
model->setHeaderData(0, Qt::Horizontal, Qt::CheckStateRole );
model->setHeaderData(1, Qt::Horizontal, QObject::tr("Name"));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("Dept"));
model->setHeaderData(3, Qt::Horizontal, QObject::tr("Section"));

addModel(model, check,"Ansar", "Prodution","Testing");
return model;

}