PDA

View Full Version : Use Designer to create Table View, How to handle the edit event on Table View?



Kevin Hoang
1st April 2010, 17:33
Somebody help me a way...

faldzip
1st April 2010, 18:47
Somebody help me a way...
First, explain your problem to 'somebody'. Until now we can't help you much. What do you understand by 'edit event'? Do you know what is a Model/View architecture and how it works in Qt?

waynew
2nd April 2010, 01:15
You don't create table views with the designer.
Do it like this:



model = new QSqlTableModel(this, <QSqlDatabase>);
view = new QTableView();
view->setModel(model);
model->setTable(<table name>);
header = new QHeaderView(Qt::Horizontal, this);


Don't forget the declarations for the model, view and header in the .h file.

Set your header column names with model->setHeaderData(<col>, Qt::Horizontal, "col name");
You can edit the data by clicking in the table cells.
Check out the doc here: http://doc.trolltech.com/4.5/model-view-programming.html

Kevin Hoang
2nd April 2010, 11:38
Thanks!

I mean that, I want to control it, such as: when users try to edit a cell, the default of this cell is a short name off previous cell, how to do like that?

waynew
2nd April 2010, 22:49
I'm not quite sure I understand what you are trying to do. But if you are trying to modify the contents of a table cell when a user clicks on it, you first need to determine which cell by using QModelIndexList QItemSelectionModel::selectedIndexes () to get the index of the selected cell.

Kevin Hoang
3rd April 2010, 05:07
@waynew: I know that features, but I want to process over default functions.
An example: I want to make a auto complete function for editing