Results 1 to 2 of 2

Thread: Tree View - cannot edit check box

  1. #1
    Join Date
    Mar 2010
    Posts
    107
    Thanks
    22
    Qt products
    Qt4
    Platforms
    Windows

    Default Tree View - cannot edit check box

    Hi
    I am developing a tree widget and have created a class for the tree items and a class for the model.
    I can add items to the model and have them displayed in the tree view widget.
    Each item has a check box and this is displayed, However, I cannot make the check box change value.
    I have attached my source and would be grateful if someone could tell me what I ahve done wrong

    Thanks

    Graham
    Attached Files Attached Files

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Tree View - cannot edit check box

    Each item has a check box and this is displayed, However, I cannot make the check box change value
    You need to write the checked status to the model, this should done in setData() method, I have added, it works. check this out.

    Qt Code:
    1. bool ReportModel::setData(const QModelIndex& index, const QVariant& value, int role)
    2. {
    3. qDebug() << "ReportModel::setData";
    4. if(role == Qt::CheckStateRole)
    5. {
    6. ReportEditorTreeItem* item = getItem(index);
    7. if(index.column() == 0)
    8. item->setIncluded(value.toBool());
    9. }
    10. emit dataChanged(index,index);
    11. return true;
    12. }
    To copy to clipboard, switch view to plain text mode 

    SimpleTree_1.zip
    Last edited by Santosh Reddy; 1st June 2011 at 20:00. Reason: spelling corrections

Similar Threads

  1. How to check the changes/Edit done on the form onStackWidget
    By Ratheendrans in forum Qt Programming
    Replies: 1
    Last Post: 25th November 2010, 12:29
  2. Qt tree widget with check boxes iteration
    By denton17 in forum Newbie
    Replies: 1
    Last Post: 9th November 2010, 14:24
  3. Replies: 5
    Last Post: 3rd April 2010, 04:07
  4. how to create a tree with check on branch?
    By richardander in forum Qt Programming
    Replies: 3
    Last Post: 8th January 2009, 16:57
  5. Check and Uncheck on a Dir Tree?
    By vishal.chauhan in forum Qt Programming
    Replies: 2
    Last Post: 3rd July 2007, 11:55

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.