qt里怎样在tablewidget添加其他对话框的数据
如下图,我想要将这个对话框的所有内容都添加到tablewidget里,怎么做,麻烦会的大神给一份代码,我用UI做的...
如下图,我想要将这个对话框的所有内容都添加到tablewidget里,怎么做,麻烦会的大神给一份代码,我用UI做的
展开
1个回答
展开全部
我这个是点击保存后将姓名,ID和眼别用信号发送:
然后在tablewidget的类里面是这样处理的:
void AddPatientWidget::on_pushButton_Save_clicked()
{
emit PostPatientInfoSig(ui->lineEdit_Name->text(),ui->lineEdit_Id->text(),\
ui->comboBox_Eye->currentText());
dataEvaluation();
writeToDataBase();
clearData();
close();
}
void HomePage::ReceivePatientInfiSlot(QString name,QString ID,QString eyes)
{
if(name != "" && ID != "")
{
//如果name,ID,eyes在表中,则返回
for(int i=0;i<ui->tableWidgetQuarantine->rowCount();i++)
{
for(int j=0;j<ui->tableWidgetQuarantine->columnCount();j++)
{
if(ui->tableWidgetQuarantine->item(i,j)!=NULL)
{
if(name == ui->tableWidgetQuarantine->item(i,0)->text() && \
ID == ui->tableWidgetQuarantine->item(i,1)->text() && \
eyes == ui->tableWidgetQuarantine->item(i,2)->text())
{
return;
}
}
}
}
QIcon icon;
icon.addFile(":/new/prefix1/images/new.png", QSize(32,32));
//将name,ID,eyes插入表中
int row = ui->tableWidgetQuarantine->rowCount();
ui->tableWidgetQuarantine->setRowCount(row + 1);
ui->tableWidgetQuarantine->setItem(row, 0, new QTableWidgetItem(icon,name));
ui->tableWidgetQuarantine->setItem(row, 1, new QTableWidgetItem(ID));
ui->tableWidgetQuarantine->setItem(row, 2, new QTableWidgetItem(eyes));
for (int i = 0; i < 3; ++i)
{
ui->tableWidgetQuarantine->item(row, i)->setTextAlignment(Qt::AlignCenter);
}
ui->tableWidgetQuarantine->sortByColumn(0, Qt::AscendingOrder);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询