Results 1 to 3 of 3

Thread: getting the checkbox value instantly from treeview model

  1. #1
    Join Date
    Jul 2009
    Location
    Jordan, and UAE
    Posts
    55
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default getting the checkbox value instantly from treeview model

    Hello All,

    I have a standard treeview model that contains checkboxes

    I'm trying to get the current status of the checkbox when a user clicks on an item, this click could either be on that element, or on the checkbox (selecting or deselecting)

    my problem is that its always giving me the previous status, not the current one, this is my code, and please see if you can help me figure how to solve this

    I've tried connecting the below slot to the clicked(), activated(), and pressed() signal, and its always the same behavior

    Qt Code:
    1. void myclass::treeViewClicked(QModelIndex index)
    2. {
    3. if(!index.isValid())
    4. return;
    5.  
    6. if(index.column() != 0)
    7. return;
    8.  
    9. ui->treeView->update(index);
    10.  
    11. if (ui->treeView->model()->data(index, Qt::CheckStateRole) == Qt::Checked)
    12. {
    13. qDebug() << "Selected";
    14. ui->treeView->selectionModel()->select(index, QItemSelectionModel::Select | QItemSelectionModel::Rows);
    15. //ui->treeView
    16. }
    17. else
    18. {
    19. qDebug() << "NOTTTT Selected";
    20. ui->treeView->selectionModel()->select(index, QItemSelectionModel::Deselect | QItemSelectionModel::Rows);
    21. }
    22. }
    To copy to clipboard, switch view to plain text mode 

    even if i click on the checkbox, and select it, it will only show me the previous stat, not the current one

    Thank you very much

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 162 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: getting the checkbox value instantly from treeview model

    why don't you connect to dataChanged() instead?

  3. The following user says thank you to caduel for this useful post:

    yazwas (27th September 2009)

  4. #3
    Join Date
    Jul 2009
    Location
    Jordan, and UAE
    Posts
    55
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: getting the checkbox value instantly from treeview model

    Thanks caduel

    that worked very well

Similar Threads

  1. Threaded refreshing of a TreeView with custom model
    By CLRS530 in forum Qt Programming
    Replies: 4
    Last Post: 25th August 2009, 08:23
  2. How can I center a checkbox in a treeview?
    By 3str in forum Qt Programming
    Replies: 1
    Last Post: 14th June 2009, 06:47
  3. A few queries about Model View Programming
    By montylee in forum Qt Programming
    Replies: 46
    Last Post: 2nd March 2009, 08:36
  4. Treeview and custom model
    By steg90 in forum Qt Programming
    Replies: 8
    Last Post: 15th May 2007, 13:54
  5. TreeView custom model
    By steg90 in forum Newbie
    Replies: 1
    Last Post: 9th May 2007, 10:06

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.