How can I prevent QDialog class from closing after \"Ok\" button was pressed? I need to close the window only if the some actions were performed correctly on this dialog, in
The same as from @kuba-ober, but using custom property. Change one function:
void QDialogValidator::checkValidity(QLineEdit * l) {
if (!l) return;
QString text = l->text();
int pos;
bool isValid = l->validator()->validate(text, pos) == QValidator::Acceptable;
setSelect(m_validWidgets, isValid, (QWidget*)l);
if (!l->property("invalid").toBool() != isValid) {
l->setProperty("invalid", !isValid);
l->style()->unpolish(l);
l->style()->polish(l);
}
emit newValidity(m_validWidgets.count() == m_needsValid);
}
Now styleSheet...
functions are not necessary but we need to add constant style sheet for the dialog or application:
d.setStyleSheet("*[invalid=\"true\"] { background: yellow }");
Or if use Qt designer, add root widget property:
*[invalid="true"] { border-style: solid; border-width: 1px; border-radius: 2px; border-color: yellow; }