PDA

View Full Version : How to perform some action on checking and unchecking te checkbox.



Ketan Shah
25th May 2011, 15:09
Hii, can any1 tell me what function is used to perform some action on checking or unchecking the checkbox in a listview..
below is my code, it shows the checkboxes in the listview…plz help..


QStandardItemModel *model;
QListView *view;
QStandardItem *parentItem;
QStandardItem *myitem;

fileTypes << “_*.dll” ;
dir.setPath(“E:/qtpro/ext”);
dir.setNameFilters(fileTypes);
files = dir.entryList();

model = new QStandardItemModel(centralWidget);
parentItem = model->invisibleRootItem();
for (int i = 0; i < files.size(); ++i)
{
fileInfo = files.at(i);
myitem = new QStandardItem();
myitem->setText(QString(”%0”).arg(fileInfo.fil eName()));
model->setItem(i, myitem);
myitem->setCheckable(true);
}
view = new QListView(centralWidget);
view->setGeometry(10, 20, 256, 192);
view->setModel(model);

wysota
25th May 2011, 15:37
Checking/Unchecking the box makes the model emit the dataChanged() signal for the respective index.

Ketan Shah
26th May 2011, 15:16
can you please give me a sample code, describing how I could do it..

FelixB
26th May 2011, 15:27
I'd suggest to start with reading the documentation of QAbstractItemModel::dataChanged(...) (http://doc.qt.nokia.com/latest/qabstractitemmodel.html#dataChanged)

wysota
26th May 2011, 16:11
can you please give me a sample code, describing how I could do it..

You connect the signal to a custom slot and in the slot do the stuff you want to do.

DanH
27th May 2011, 03:51
Read up on signals & slots (http://doc.qt.nokia.com/4.7/signalsandslots.html).