Qt model和tableview的使用

mac2022-06-30  73

QT中的model和tableview都是采用index索引   index含有两个成员变量一个是row   一个是column  对应该索引的行号、列号

model提供数据    view提供视图   view用来显示model的数据   必须将model绑定到某个view中才能显示

ui->tableView->setModel(model); ui->tableView->currentIndex();//获取选中单元格的index ui->tableView->currentIndex().column();//当前选中单元格的列号 ui->tableView->currentIndex().row();//当前选中单元格行号 ui->tableView->currentIndex().data();//当前选中单元格内的数据 model->setData(ui->tableView->currentIndex(),tr("123"));//设置当前选中单元格的数据为字符串123 //遍历model中的所有数据 //model->rowCount()获取model的行数 //model->columnCount()获取model的列数 for(int i=0;i<model->rowCount();i++) { for(int j=0;j<model->columnCount();j++) { QMessageBox::warning(this,"",model->data(model->index(i,j)).toString()); } }

 

转载于:https://www.cnblogs.com/zhaocundang/p/4684671.html

最新回复(0)