tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);//双击不能修改表的属性设置
size = 7;
model->setColumnCount(size);//列
model->setRowCount(size+10);//行
model->setHeaderData(0,Qt::Horizontal,"患者ID");
model->setHeaderData(1,Qt::Horizontal,"患者姓名");
model->setHeaderData(2,Qt::Horizontal,"性别 ");
model->setHeaderData(3,Qt::Horizontal,"年龄");
model->setHeaderData(4,Qt::Horizontal,"医生");
model->setHeaderData(5,Qt::Horizontal,"电话");
model->setHeaderData(6,Qt::Horizontal,"身份证");
model->setHeaderData(7,Qt::Horizontal,"住址");
for(int i=0;i<size;i++)
{
QStandardItem *itemID = new QStandardItem("121111101110");
model->setItem(i,0,itemID);
QStandardItem *itemUser = new QStandardItem("黎明");
model->setItem(i,1,itemUser);
QStandardItem *itemPassWd = new QStandardItem("男");
model->setItem(i,2,itemPassWd);
}
tableView->setModel(model);
tableView->verticalHeader();
tableView->setColumnWidth(0,80);
tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
tableView->resize(800,480);
tableView->show();
connect(tableView,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(showdetail(QModelIndex)));//这是槽函数
void MainWindow::showdetail(QModelIndex index)//获取双击当前行的数据
{
qDebug()<<"The result = "<< index.data().toString();
findPerson->show();
findPerson->Display();
}