Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make QDialogButtonBox NOT close its parent QDialog?

Tags:

c++

dialog

qt

I have a QDialog with a QDialogButtonBox widget, and I've connected the button box's accepted signal to a slot in my QDialog subclass, like so:

void MyDialog::on_buttonBox_accepted()
{
    QString errorString = this->inputErrorString();
    if (errorString.isEmpty())
    {
        // Do work here
        // code code code...

        this->accept();
    }
    else
    {
        QMessageBox::critical(this, tr("Error"), tr("The following input errors have occurred:") + errorString);
    }
}

However, the dialog is closes after the message box is displayed; apparently the button box automatically connects its accepted signal to QDialog's accept slot (I want to call that slot manually). How can I prevent this so I can take the manual approach outlined above?

like image 946
Jake Petroules Avatar asked Dec 09 '22 14:12

Jake Petroules


1 Answers

You can implement MyDialog::accept(). The function is virtual in QDialog.

like image 90
Lars Avatar answered Dec 12 '22 04:12

Lars