Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

how to load enter data in qtable view?



  • This post is deleted!


  • First thing you need is a model to add data and then you can use QTableView to show your data. You can use QStandardItemModel for now, as it is easier to handle data as a beginner.

    Follow this to understand how the model works with a view.

    To insert rows may be this will help you.



  • @Nayan-Thapa-Magar

    1. Write your model, with columns quantity, rate, total, product name. You might use a custom model, a QStandardItemModel or a QSqlTableModel if you are using an actual database. Store the numeric columns to hold numbers, not strings.

    2. Add a QTableView for the model. Alternatively, you could make it a QTableWidget, in which the case model mentioned in #1 will already be attached to it (QTableWidget has its own inbuilt model).

    3. Get that working to display whatever rows the table has.

    4. Easiest is if you add something like QPushButton just below (not inside) the table. Clicking it adds a new, blank row at the end of the table, for a new item. Or have dedicated widgets for the user to pick what he wants and a button to add that as the row. There are other ways too.

    5. (Probably) extend the QTableWidget/QTableView to allow columns Modify and Remove with their own buttons against each row.

    For adding/modifying you have a choice: you can have dedicated widgets outside the table where you copy rows/do your editing, or you can make your QTableWidget/QTableView allow editing in selected row, changing values inside the actual row.

    That's the outline.


Log in to reply