Results 1 to 5 of 5

Thread: Checkbox in QTreeView

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2011
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Checkbox in QTreeView

    Hi,
    I need to add checkboxes to the first three columns in a QTreeView which gets its data
    from a QAbstractItemModel .
    Could some one tell me how to complete my model, so that the user can freely check and uncheck theses checkboxes.


    Qt Code:
    1. QModelIndex OutputsListModel::index ( int row, int column, const QModelIndex & parent) const
    2. {
    3. return createIndex(row, column);
    4. }
    5. QModelIndex OutputsListModel::parent ( const QModelIndex & index ) const
    6. {
    7. return QModelIndex();
    8. }
    9.  
    10. int OutputsListModel::rowCount ( const QModelIndex & parent) const
    11. {
    12. return(r);
    13. }
    14. int OutputsListModel::columnCount ( const QModelIndex & parent) const
    15. {
    16. return(c);
    17. }
    18. bool OutputsListModel::hasChildren ( const QModelIndex & parent ) const
    19. {.....
    20. }
    21. QVariant OutputsListModel::data ( const QModelIndex & index, int role) const
    22. { int i = index.column();
    23. if(role == Qt::DisplayRole)
    24. {.....
    25. }
    26. }
    27. Qt::ItemFlags OutputsListModel::flags(const QModelIndex& index) const
    28. {
    29. if (i == 0 || i== 1 || i == 2)
    30. return Qt::ItemIsUserCheckable | Qt::ItemIsSelectable | Qt::ItemIsEnabled;
    31. return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
    32. }
    33. bool OutputsListModel::setData(const QModelIndex& index, const QVariant& value, int role)
    34. {
    35. return true;
    36. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by mugi; 8th July 2011 at 23:15.

Similar Threads

  1. Replies: 3
    Last Post: 1st April 2011, 04:58
  2. Replies: 0
    Last Post: 5th July 2010, 09:05
  3. QTreeView, checkbox problem
    By jwieland in forum Qt Programming
    Replies: 3
    Last Post: 23rd April 2009, 14:09
  4. How to set StyleSheet for checkbox in QTreeView;
    By visor_ua in forum Qt Programming
    Replies: 3
    Last Post: 7th April 2009, 11:46
  5. QTreeView: How to center a checkbox in a cell
    By chezifresh in forum Qt Programming
    Replies: 3
    Last Post: 19th December 2008, 12:11

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.