PDA

View Full Version : building a basic grid (urgent)



sattu
21st September 2010, 08:12
Hi everyone!
I had created a database and in it a table(named USER). Then by giving the command "select * from user" and ui->tableview->setModel(obj), i could display the contents of database in a tableview in form of a grid. But now i want to create a grid manually without using database. All the fields like id,name,address should be entered manually and then the contents displayed in a tableview. Can any one please tell me how to do it, please?:confused:

wysota
21st September 2010, 08:41
You need to have your own model attached to the table view. You may use QStandardItemModel.

sattu
21st September 2010, 09:04
:confused:
You need to have your own model attached to the table view. You may use QStandardItemModel.
Ok fine. I have to use that class. But how do i insert the field names like ID, NAME, ADDRESS and then the corresponding values for it? So many commands are there, i'm confused to use which one for which?

marcvanriet
21st September 2010, 11:49
Hi,

You could also use a QTableWidget. Then you can very easily first define the colums using the editor in Qt Designer. Then in your program you can loop over all your records and add rows to the tablewidget.

Best regards,
Marc

sattu
21st September 2010, 11:55
thanks, but i did it in a slightly different way after seeing the example of "custom sort/filter model".

With regards,

wysota
21st September 2010, 12:01
But how do i insert the field names like ID, NAME, ADDRESS and then the corresponding values for it?
For the former use QStandardItemModel::setHorizontalHeaderLabels(). For the latter use QStandardItemModel::appendRow()