PDA

View Full Version : QTreeView + QListWidget checkboxes.How to see if returned index is checked/uncheched.



mekos
23rd July 2008, 19:12
Hello

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



//listWidget creation
{
QListWidgetItem* item1 = new QListWidgetItem (tr( "string1"));
item1->setCheckState ( Qt::Checked );
QListWidgetItem* item2 = new QListWidgetItem (tr( "string2 ));
item2->setCheckState ( Qt::Unchecked );
}

//and the below function must find if the selected index from the QListWidget is checked,and do something inside:

void function::check(const QModelIndex &index)
{
//what code should it be here???
//if checked do thing1
//if unchecked do thing2
}


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



QStandardItemModel *model::createTree( )
{
while ( ( condition ) )
{
QModelIndex index = model->index ( 0, 0 );
model->insertRow ( 0 );
if (condition==contition2)
{
model->setData ( index, someString);
model->setData ( index, Qt::Checked, Qt::CheckStateRole );
}
else
{
model->setData ( index, someString);
model->setData ( index, Qt::Unchecked, Qt::CheckStateRole );
}

}
}
//so i have a model with checked and unchecked checkboxes
//the tree gets the model with setModel and the i have to create a function that checks is the index is checked/unchecked:

void function::check(const QModelIndex &index)//the tree's index this time
{
//what code should it be here???
//if checked do thing1
//if unchecked do thing2
}





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!

ru_core
23rd July 2008, 19:21
try to look sideward QItemDelegate class, namely the item about Standard Roles and Data Types

mekos
23rd July 2008, 21:20
Hello

can you pass me an example that fits in the check function?

wysota
25th July 2008, 15:30
Use QAbstractItemModel::data() with Qt::CheckStateRole role - it contains the information whether a particular item is checked.