Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to perform some action on checking or unchecking the checkbox..
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 5.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Ketan Shah
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Franzk
      wrote on last edited by
      #2

      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.

      "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • K Offline
          K Offline
          Ketan Shah
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved