Results 1 to 4 of 4

Thread: QTreeView + QListWidget checkboxes.How to see if returned index is checked/uncheched.

  1. #1
    Join Date
    Dec 2007
    Posts
    28
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Post QTreeView + QListWidget checkboxes.How to see if returned index is checked/uncheched.

    Hello

    Assume i have a QListWidget with 2 items an both have checkboxes.

    Qt Code:
    1. //listWidget creation
    2. {
    3. QListWidgetItem* item1 = new QListWidgetItem (tr( "string1"));
    4. item1->setCheckState ( Qt::Checked );
    5. QListWidgetItem* item2 = new QListWidgetItem (tr( "string2 ));
    6. item2->setCheckState ( Qt::Unchecked );
    7. }
    8.  
    9. //and the below function must find if the selected index from the QListWidget is checked,and do something inside:
    10.  
    11. void function::check(const QModelIndex &index)
    12. {
    13. //what code should it be here???
    14. //if checked do thing1
    15. //if unchecked do thing2
    16. }
    To copy to clipboard, switch view to plain text mode 

    I have to do the same thing with a QTreeView:
    here's an exampe of the tree implementation:

    Qt Code:
    1. QStandardItemModel *model::createTree( )
    2. {
    3. while ( ( condition ) )
    4. {
    5. QModelIndex index = model->index ( 0, 0 );
    6. model->insertRow ( 0 );
    7. if (condition==contition2)
    8. {
    9. model->setData ( index, someString);
    10. model->setData ( index, Qt::Checked, Qt::CheckStateRole );
    11. }
    12. else
    13. {
    14. model->setData ( index, someString);
    15. model->setData ( index, Qt::Unchecked, Qt::CheckStateRole );
    16. }
    17.  
    18. }
    19. }
    20. //so i have a model with checked and unchecked checkboxes
    21. //the tree gets the model with setModel and the i have to create a function that checks is the index is checked/unchecked:
    22.  
    23. void function::check(const QModelIndex &index)//the tree's index this time
    24. {
    25. //what code should it be here???
    26. //if checked do thing1
    27. //if unchecked do thing2
    28. }
    To copy to clipboard, switch view to plain text mode 



    Could this be done the same way as the QListWidget or the implementation of the check function should be diffferent for those two occasions?

    Thanks!

  2. #2
    Join Date
    Mar 2008
    Posts
    25
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeView + QListWidget checkboxes.How to see if returned index is checked/unchec

    try to look sideward QItemDelegate class, namely the item about Standard Roles and Data Types

  3. #3
    Join Date
    Dec 2007
    Posts
    28
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTreeView + QListWidget checkboxes.How to see if returned index is checked/unchec

    Hello

    can you pass me an example that fits in the check function?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTreeView + QListWidget checkboxes.How to see if returned index is checked/unchec

    Use QAbstractItemModel::data() with Qt::CheckStateRole role - it contains the information whether a particular item is checked.

  5. The following user says thank you to wysota for this useful post:

    mekos (29th July 2008)

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.