PDA

View Full Version : Set up a table view



kais khelifa
10th November 2011, 23:12
Hello,

I'm new to Qt and i'm trying to set up a table view that uses a csv file to fill. i managed to read the csv file and i'm stuck with the table view. i read a lot of documentation about it but i don't know how to start.
i know i have to create a model and then the table view but i dont seem to get i tto work, any help !!
If any one have an explained example of a table view (even with 1 or 2 columns ) that would be really helpful.

THanks
K|Z

Santosh Reddy
10th November 2011, 23:37
i know i have to create a model and then the table view but i dont seem to get i tto work, any help !!
What is the problem with the model? how far did you go? Show how you re-implemented the virtual calls.

kais khelifa
11th November 2011, 20:12
i just started, I'm very new to this so don't panic :D
i added a tableview (tableDisplay) to my MainWindow and i stopped there.
i managed to do some good stuff (reading csv file, filling a vector, ....), but i've never worked with tableviews.
i don't know where to begin.

grin
11th November 2011, 21:14
Hi =)
As start you can use QTableWidget (it's same QTableView and contains model inside). Every cell of table is a QTableWidgetItem.
http://doc.qt.nokia.com/stable/qtreewidget.html#details

As next step you can replace QTableWidget by QTableView + QStandartItemModel
(instead of QTableWidgetItem you will operate with QStandartItem).
http://doc.qt.nokia.com/stable/qstandarditemmodel.html#details

Then you can create you fully customized model from QAbstractItemModel.
I think this is a good way (from simple to complex).

This example can be useful for you
http://doc.qt.nokia.com/stable/itemviews-simpletreemodel.html