If I morph the table widget to TableView, the designer doesn't have the option of defining the number of rows and columns, how do I do that? In the program?
The table view uses the model to determine how many rows and columns there are. There are no setRowCount() or setColumnCount() methods for QTableView for that reason. When the model tells the table view it needs to update (because the model has changed), the table view asks the model for the number of rows and columns and uses that to configure itself.
You want to do something like this:
// Not real C++ code...
void MainWindow::init()
{
// open the file, etc.
// create the model
for each line in the file
{
parse the line into fields
for each field
{
items.push_back( pItem );
}
pModel->appendRow( items );
}
// close the file, etc.
// set the model on the table VIEW
ui->tableView->setMode( pModel );
}
// Not real C++ code...
void MainWindow::init()
{
// open the file, etc.
// create the model
QStandardItemModel * pModel = new QStandardItemModel( this );
for each line in the file
{
QList< QStandardItem * > items;
parse the line into fields
for each field
{
QStandardItem * pItem = new QStandardItem( field );
items.push_back( pItem );
}
pModel->appendRow( items );
}
// close the file, etc.
// set the model on the table VIEW
ui->tableView->setMode( pModel );
}
To copy to clipboard, switch view to plain text mode
Bookmarks