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!
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!