Results 1 to 6 of 6

Thread: QStandardItemModel

  1. #1
    Join Date
    Jan 2016
    Posts
    81
    Thanks
    31
    Qt products
    Qt5
    Platforms
    Windows

    Default QStandardItemModel

    Hi,

    I want to bind QStandardItemModel to a table(TableView or GridView or ...) with several rows and columns.

    Table must have not any scroll and height of table is equal of count of row.

    I can show QStandardItemModel in tableview but height of it more than from count of row.

    I can show QStandardItemModel in GridView but it can show just one record.

    Please gide me.

    Qt Code:
    1. TableView {
    2. id: tablemodel
    3. anchors.fill: parent
    4.  
    5. model: myXML.newMyModel
    6.  
    7.  
    8. MyTableViewColumn {
    9. role: "field1"
    10. }
    11. MyTableViewColumn {
    12. role: "field2
    13. }
    14. MyTableViewColumn {
    15. role: "field3
    16. }
    17. MyTableViewColumn {
    18. role: "field4
    19. }
    20. }
    21.  
    22.  
    23.  
    24. GridView {
    25. anchors.fill: parent
    26. model: myXML.newMyModel
    27.  
    28. delegate: Rectangle {
    29. Text {
    30. text: field1
    31. }
    32. Text {
    33. text: field2
    34. }
    35. Text {
    36. text: field3
    37. }
    38. Text {
    39. text: field4
    40. }
    41. Text {
    42. text: field5
    43. }
    44. Text {
    45. text: field6
    46. }
    47. }
    48. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QStandardItemModel

    Well, this obviously isn't the code you are using.

    Can you show the roleNames() implementation of your QStandardItemModel subclass and how you create a "row" item?

    Cheers,
    _

  3. #3
    Join Date
    Jan 2016
    Posts
    81
    Thanks
    31
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QStandardItemModel

    Thank you.

    Quote Originally Posted by anda_skoa View Post
    Can you show the roleNames() implementation of your QStandardItemModel subclass and how you create a "row" item?
    _



    Qt Code:
    1. QHash<int, QByteArray> roleNames() const{
    2. QHash<int, QByteArray> roles;
    3. roles[index] = "index";
    4. roles[first] = "first";
    5. roles[avg] = "avg";
    6. roles[time] = "time";
    7. roles[niro] = "force";
    8. roles[method] = "method";
    9. roles[zoom] = "zoom";
    10. roles[image] = "image";
    11. return roles;
    12. }
    13.  
    14. QString MyXML::readXMLFile(QString fileName)
    15. {
    16. QFile file(fileName);
    17. if (!file.open(QFile::ReadOnly | QFile::Text))//Error: Cannot read file
    18. return "";
    19.  
    20. QXmlStreamReader reader(file.readAll());
    21. file.close();
    22.  
    23. newMyModel->clear();
    24.  
    25. while(!reader.atEnd()) {
    26. reader.readNext();
    27. if (reader.isStartElement()) {
    28.  
    29. QXmlStreamAttributes attributes = reader.attributes();
    30.  
    31.  
    32. it->setData(attributes.value("index").toString(), MyModel::index);
    33. it->setData(attributes.value("first").toString(), MyModel::first);
    34. it->setData(attributes.value("avg").toString(), MyModel::avg);
    35. it->setData(attributes.value("time").toString(), MyModel::time);
    36. it->setData(attributes.value("force").toString(), MyModel::force);
    37. it->setData(attributes.value("method").toString(), MyModel::method);
    38. it->setData(attributes.value("zoom").toString(), MyModel::zoom);
    39. it->setData(attributes.value("image").toString(), MyModel::image);
    40.  
    41. newMyModel->appendRow(it);
    42. }
    43. }
    44.  
    45. return fileName;
    46. }
    47. TableView {
    48. id: tablemodel
    49. anchors.fill: parent
    50.  
    51. model: myXML.newMyModel
    52.  
    53. MyTableViewColumn {
    54. role: "index"
    55. title: "index"
    56. }
    57. MyTableViewColumn {
    58. role: "zoom"
    59. title: "zoom"
    60. }
    61.  
    62. MyTableViewColumn {
    63. role: "avg"
    64. title: "avg"
    65. }
    66.  
    67. MyTableViewColumn {
    68. role: "first"
    69. title: "first"
    70.  
    71. }
    72.  
    73. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QStandardItemModel

    That looks good.
    So you are saying that if you do this
    Qt Code:
    1. GridView {
    2. anchors.fill: parent
    3. model: myXML.newMyModel
    4.  
    5. delegate: Text {
    6. text: "index"
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 
    you are only getting one item in the grid?

    Cheers,
    _

  5. #5
    Join Date
    Jan 2016
    Posts
    81
    Thanks
    31
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QStandardItemModel

    Thank you
    Quote Originally Posted by anda_skoa View Post
    Qt Code:
    1. GridView {
    2. anchors.fill: parent
    3. model: myXML.newMyModel
    4.  
    5. delegate: Text {
    6. text: "index"
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 
    you are only getting one item in the grid?

    _

    Yes

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QStandardItemModel

    Very strange.
    What's the value of the GridView's count property?

    Have you tried with a ListView just to check that you can access all model data?

    Cheers,
    _

  7. The following user says thank you to anda_skoa for this useful post:

    neda (2nd May 2016)

Similar Threads

  1. QStandardItemModel principle
    By bmn in forum Qt Programming
    Replies: 3
    Last Post: 1st March 2016, 20:19
  2. QStandardItemModel and QML listView
    By nilhcraiv in forum Qt Quick
    Replies: 0
    Last Post: 23rd March 2013, 01:42
  3. using QStandardItemModel
    By GrahamLabdon in forum Newbie
    Replies: 1
    Last Post: 6th March 2011, 09:13
  4. QStandardItemModel Help
    By frenk_castle in forum Newbie
    Replies: 1
    Last Post: 16th January 2010, 17:54
  5. QStandardItemModel alignment
    By Pembar in forum Qt Programming
    Replies: 1
    Last Post: 10th July 2009, 16:07

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.