How dont close the dialog window if Ok in ButtonBox is clicked but some condition is not true
-
If the WidgetCell will empty when I press OK it closes, but I would like it doesn't close, hope your ideas help me to resolve the problem, thanks.
my code
-
Hi,
You need to control in real time your QLineEdits (with textEdited() signal I presume)
checking the validity of them in the slot method and enabled the OK button accordingly:QPushButton * okBut=ui->buttonBox->button(QDialogButtonBox::Ok); if(valid) // all the fields are valid okBut->setEnabled(true); else okBut->setEnabled(false);
You problably also need to set the OK button to false (disabled) when the dialog show up.
-
@mpergand thanks,Yes you are right I do it in a such way
connect(line, SIGNAL(textChanged(const QString &)), this, SLOT(DBsearching(const QString &)));
void Dialog::DBsearching(const QString & s)
{
for(int row = 0; row<ui->tableWidget->rowCount();row++)
{
QLineEdit l = ui->tableWidget->cellWidget(row,2)->findChild<QLineEdit>();
if(!true_city(l))
{
ui->buttonBox->setEnabled(false);
return;
}
}
ui->buttonBox->setEnabled(true);
return;
}