Results 1 to 2 of 2

Thread: QStandardItemModel Help

  1. #1
    Join Date
    Sep 2009
    Location
    Belgrade, Serbia
    Posts
    40
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QStandardItemModel Help

    I have three tree views in my application and every view have its model which basically looks like this:

    Qt Code:
    1. |
    2. |
    3. |--------Printer1
    4. | |
    5. | |------------Tray1
    6. | | |
    7. | | |----------Paper type
    8. | | |----------value
    9. | | |----------Amount
    10. | | |----------value
    11. | |
    12. | |------------Tray2
    13. | |
    14. | |----------Paper type
    15. | |----------value
    16. | |----------Amount
    17. | |----------value
    18. |
    19. |--------Printer2
    20. | |
    21. | |------------Tray1
    22. | | |
    23. | | |----------Paper type
    24. | | |----------value
    25. | | |----------Amount
    26. | | |----------value
    27. | |
    28. | |------------Tray2
    29. | |
    30. | |----------Paper type
    31. | |----------value
    32. | |----------Amount
    33. | |----------value
    34. |
    35. |--------Printer3
    36. |
    37. |------------Tray1
    38. | |
    39. | |----------Paper type
    40. | |----------value
    41. | |----------Amount
    42. | |----------value
    43. |
    44. |------------Tray2
    45. |
    46. |----------Paper type
    47. |----------value
    48. |----------Amount
    49. |----------value
    To copy to clipboard, switch view to plain text mode 

    I have a function which creates this empty model. Every value field is empty. I need to be able to do three things:

    One: When the user chooses the type of paper he wants for a specific tray on a specific printer and the amount of paper he need I need to set the corresponding value fields.

    Two: I need to reset the model, clear all values.

    Three: I need to retrieve all values, for storing, printing etc.

    I thought about making new model every time and copying it to the model that is associated to the view but I am not sure since model inherits QObject plus it doesn't solve my need number three. I am sure there is an answer in the documentation but so far I failed to find it. If somebody could help me save some time and tell me where to look for a class or a function to use it would really help me.

    All I need is a way to set and get the value of the specific item in the model.

    Thanks in advance.

  2. #2
    Join Date
    Nov 2009
    Posts
    129
    Thanks
    4
    Thanked 29 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QStandardItemModel Help

    Quote Originally Posted by frenk_castle View Post
    All I need is a way to set and get the value of the specific item in the model.
    Since you imply by the title that you’re using a QStandardItemModel, there are two ways you can access the data: you can employ the basic model/view technique and use QStandardItemModel::setData and QStandardItemModel::data; or you can follow the item-based approach and useQStandardItemModel::item or QStandardItemModel::itemFromIndex to access a QStandardItem and then use that class’s methods to proceed.

    You can mix these approaches; QStandardItemModel is just a QAbstractItemModel that uses instances of QStandardItem as its data store. Sometimes one way of accessing the data may be simpler and sometimes the other.

Similar Threads

  1. Best practices concerning QStandardItemModel
    By tim47 in forum Qt Programming
    Replies: 2
    Last Post: 27th January 2010, 05:29
  2. QStandardItemModel alignment
    By Pembar in forum Qt Programming
    Replies: 1
    Last Post: 10th July 2009, 16:07
  3. Print QStandardItemModel
    By Mrdata in forum Newbie
    Replies: 1
    Last Post: 4th July 2007, 23:14
  4. QTreeView with QStandardItemModel
    By steg90 in forum Newbie
    Replies: 3
    Last Post: 16th May 2007, 09:28
  5. can't do a QTreeView with a QStandardItemModel
    By Nuria in forum Qt Programming
    Replies: 4
    Last Post: 27th July 2006, 00:41

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.