QT QTableWidgetItem是用户编辑而不是自动填充
2021-09-18 本文已影响0人
c之气三段
connect(ui->tableWidget,&QTableWidget::itemDoubleClicked,this,&MonitorParaWidget::slot_editor);
connect(ui->tableWidget,&QTableWidget::itemChanged,this,&MonitorParaWidget::slot_itemCheck);
void MonitorParaWidget::slot_editor(QTableWidgetItem* item)
{
ui->label_tip->clear();
m_isUserEditorSuccessful = false;
m_currentItemText = item->text();
m_isUserEditor = true;//是用户编辑
}
void MonitorParaWidget::slot_itemCheck(QTableWidgetItem* item)
{
if(m_isUserEditor)
{
QString itemText = item->text();
if(itemText.contains(QRegExp("^[0-9]*$")))
{
m_isUserEditorSuccessful = true;//编辑成功
}
else
{
item->setText(m_currentItemText);
m_isUserEditorSuccessful = false;
ui->label_tip->setText(QObject::tr("failed"));
}
m_isUserEditor = false;
}
}