How to perform some action on checking or unchecking the checkbox..



  • 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.fileName()));
    model->setItem(i, myitem);
    myitem->setCheckable(true);
    }
    view = new QListView(centralWidget);
    view->setGeometry(10, 20, 256, 192);
    view->setModel(model);
    @

    Edit: please use @ tags around your code sections; Andre



  • Read about "signals and slots":http://doc.trolltech.com/latest/signalsandslots.html, and then connect a slot that implements your desired functionality to the checked(bool) signal.



  • Ketan, you keep on starting new topics with different approaches for using checkboxes in lists. What's wrong with the answers you got in the "previous":http://developer.qt.nokia.com/forums/viewthread/6242/ "topics":http://developer.qt.nokia.com/forums/viewthread/6205/ you started on this?



  • Sorry Sir,
    but it was for Qt3, there you only adviced me to avoid using Qt3 Support classes as they would are not going to be the part of Qt5..
    so I used Qt4 classes and I had added the checkbox in listview by using QStandardItemModel, QlistView and QStandardItem. but again I am facing 1 problem, I am not able to perform any action on checking and unchecking the checkbox..
    so I was just asking what function can be used for it to determine whether a checkbox is checked or not..
    Actually what I wanted is, when my checkbox is clicked it should display the respective item name that has been checked.....so what function I can use for it...plz help..



  • Trying another approach to the same problem, is no reason to start a new topic.

    Indeed, I did suggest that you don't use the Q3 support classes in new code, and I stand by that. You were also "suggested":http://developer.qt.nokia.com/forums/viewthread/6242/ to take a look at using a QFileSystemModel with the CheckableProxyModel class. You did not even respond to that route. Is there any reason you can not use that method? What is wrong with it?

    If you want to immediately respond to changes to the check state of your model's items, you will need to either modify (subclass) your model, or insert a proxy model. Either way, you can add a signal checkStateChanged(QModelIndex index, Qt::CheckState state) that you can emit from the setData() method of the model or proxy if that role is being changed. Of course, that would only work for when that is done from the view (or at least, through the setData interface of the model), but that would probably be enough for you. You'll need to emit that signal when the CheckStateRole is set.

    Note that the CheckableProxyModel mentioned earlier just gives you a signal checkedNodesChanged() that tells you something happened.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.