[Solved] QAbstractTableModel & QtableView querries?
-
Hi,
In my application I have allocated 2D array which stores double variables. I want to display this in the form of a spreadsheet. So I am creating a custom model by subclassing QAbstractTableModel & setting it as the model for a QTableView. I have some querries:- The table view can only be in the GUI thread. But is it possible to put the table model in a different thread? If yes, would there be any specific advantage of doing this?
- How does the table view know what data has to be displayed? I believe it uses rowCount() & columnCount() to know the dimensions of the table. Using this information it loops to determine value for each cell using data(). Is there anything else that I may have missed?
- In the table model I am storing : int size & double **array as class variables. I am updating these variables from another class. Now suppose it was containing data of size 10x10 & view was displaying this. Now I want to change the data to a 20x20 size array. After updating the class variables how should I notify the table model & table view that the data has changed?
- What does the dataChanged() SIGNAL do? Does it do anything to the table model also or just refreshes the table view?
- Do I have to use createIndex()? If yes then when?
-
Expecting some helpful answers people...
I am stuck up in my project... -
- Yes, possibly. No, probably not.
- A combination of the signals from the model, e.g. dataChanged(), rowsAboutToBeInserted(), rowsInserted() etc.
- beginInsertRows(), endInsertRows() etc. It is all in the model view overview documentation in Assistant.
- It informs any attached views (note plural) that the data for the specified index has changed in some way. The view should update itself as appropriate.
- No, the base implementation is quite likely adequate.
http://qt-project.org/doc/qt-5.0/qtcore/qabstractitemmodel.html#details
http://qt-project.org/doc/qt-5.0/qtwidgets/model-view-programming.html -
Hi Chris,
Thanks for your answer!
Works like a charm.
The documentation somehow I feel is a bit weak on this topic.
I thought ..Insert..() are required only for inserting row/column in an existing table, similar to what can be done in Excel. The documentation does not say that I have to create the table using these functions.
Anyways got it now!