Results 1 to 2 of 2

Thread: Sequence of inverted data row in Qtableview

  1. #1
    Join Date
    Jun 2018
    Posts
    31
    Thanks
    8
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Sequence of inverted data row in Qtableview

    Hi,
    I have a problem reading data from a file and presenting it in a QtableView, the sequence of the data row is reversed. I am using the insertRow (int position, int rows, const QModelIndex & index) function of the AddressBook example in the QtableModel, that is, beginInsertRows (QModelIndex (), position, position + rows - 1); .... endInsertRows (). When calling the function insertRow () I put
    int rowPosition = 0;
    tableModel-> insertRows (rowPosition, 1, QModelIndex ());
    rowPosition ++; // Number of rows I have added
    but the rows are presented in an inverted order as in the figures.
    How do I present the rows in the proper order?
    thanks for help me.
    Attached Images Attached Images

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,589
    Thanks
    13
    Thanked 1,586 Times in 1,515 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Sequence of inverted data row in Qtableview

    The beginInsertRows() and endInsertRows() functions are for use inside the model implementation around the logic that populates the model's internal data structures.
    The insertRows() function is a public API for manipulating the model content from outside the model.

    Are you implementing a table model of your own, or are you simply populating a QStandardItemModel (or similar existing model)?

    if you are doing the latter then this works:
    Qt Code:
    1. #include <QApplication>
    2. #include <QStandardItemModel>
    3. #include <QTableView>
    4. #include <QFile>
    5. #include <QTextStream>
    6.  
    7. int main(int argc, char **argv)
    8. {
    9. QApplication app(argc, argv);
    10.  
    11. model.setColumnCount(10);
    12.  
    13. QFile file("test.txt");
    14. if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
    15. return 1;
    16.  
    17. QTextStream in(&file);
    18. while (!in.atEnd()) {
    19. int row = model.rowCount();
    20. model.insertRow(row);
    21. double value;
    22. for (int col = 0; col < 10; ++col) {
    23. in >> value;
    24. model.setData(model.index(row, col), value);
    25. }
    26. in.skipWhiteSpace();
    27. }
    28.  
    29. QTableView view;
    30. view.setModel(&model);
    31. view.show();
    32. return app.exec();
    33. }
    To copy to clipboard, switch view to plain text mode 
    Test.txt:
    Qt Code:
    1. 1.23 1.12 1.19 2.12 2.22 2.01 3.1 3.2 3.01 3.1
    2. 1.70 1.11 1.88 2.01 2.10 2.92 3.01 3.12 3.21 3.2
    3. 1.70 1.11 1.88 2.01 2.10 2.92 3.01 3.12 3.21 3.2
    4. 1.12 1.30 1.91 2.11 2.31 2.11 3.22 3.11 3.45 3.5
    5. 1.34 1.12 1.65 2.01 2.09 2.09 3.11 3.44 3.55 3.1
    6. 1.90 1.13 1.34 2.07 2.08 2.06 3.01 3.02 3.02 3.4
    7. 1.12 1.34 1.89 2.03 2.07 2.03 3.32 3.11 3.21 3.1
    8. 1.12 1.34 1.89 2.03 2.07 2.03 3.32 3.11 3.21 3.1
    9. 1.12 1.34 1.89 2.03 2.07 2.03 3.32 3.11 3.21 3.1
    To copy to clipboard, switch view to plain text mode 
    Last edited by ChrisW67; 26th December 2019 at 10:34.

  3. The following user says thank you to ChrisW67 for this useful post:

    Eduardo Huerta (28th December 2019)

Similar Threads

  1. QMatrix Inverted
    By muykim in forum Newbie
    Replies: 1
    Last Post: 18th January 2018, 05:52
  2. QwtPolarSpectrogram with inverted Radius
    By ishitha92 in forum Qwt
    Replies: 5
    Last Post: 31st March 2017, 15:31
  3. Replies: 2
    Last Post: 28th January 2015, 15:27
  4. Inverted QTextEdit
    By TMan in forum Qt Programming
    Replies: 2
    Last Post: 31st July 2009, 17:35
  5. QWTdial inverted range
    By jmsbc in forum Qwt
    Replies: 1
    Last Post: 12th January 2009, 22:21

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.