PDA

View Full Version : Get The Q3CheckListItem name on checking the item



Ketan Shah
24th May 2011, 10:07
hii,
I want to get the respective name of the Q3CheckListItem on checking the respective item…
how can i do this plz help..Below is my code…

QStringList fileTypes;
QDir dir;
QFileInfo fileInfo;
QStringList files;
Q3CheckListItem *item;

listView->setResizeMode( Q3ListView::LastColumn );
listView->addColumn( “Extension” );
//view.show();
//ui->listView->header()->hide();

fileTypes << “_*.dll” ;
dir.setPath(“E:/qtpro/ext”);
dir.setNameFilters(fileTypes);
files = dir.entryList();
for (int i = 0; i < files.size(); ++i)
{
fileInfo = files.at(i);
item = new Q3CheckListItem(listView,QString(”%1”) .arg(fileInfo.fileName()),Q3CheckListItem::CheckBo x );
}

Santosh Reddy
25th May 2011, 06:21
Q3 classes are not recommend to be used for new code, it's only to support old code

There are couple of ways to do this, one of the ways would be implement a class which is a sub-class of Q3CheckListItem and use that new class to add items on the view. Then implement Q3CheckListItem::stateChange() virtual method in the new class, and use the text() method to get the name an use it.

Example:


class myItem : public Q3CheckListItem
{
public:
//add required constructors
protected:
stateChange (bool b)
{
QString item_name;
if(b == true)
{
if(state() == Q3CheckListItem::On)
{
item_name = text();
// Use item_name or whatever you want
}
}
}
};

...
for (int i = 0; i < files.size(); ++i)
{
fileInfo = files.at(i);
item = new myItem(listView,QString(”%1”).arg(fil eInfo.fileName()),Q3CheckListItem::CheckBox );
}
...