bool mem_new_phpDialog::eventFilter(QObject *o, QEvent *e){ QDate limDate; limDate.setDate(1900, 1, 1); if(e->type() == QEvent::Paint) { if(o->property("requiredField").toBool()) { QWidget * w = dynamic_cast<QWidget *>(o); if(w && w->parentWidget()) { w->parentWidget()->update(QRect(w->pos(), w->size()).adjusted(-2, -2, 2, 2)); } } else { QPainter p(qobject_cast<QWidget *>(o)); QPen pen_; pen_.setWidth(1); pen_.setColor(QColor(255, 183, 183)); // Set border color p.setPen(pen_); p.setRenderHint(QPainter::Antialiasing); bool ready_ = true; foreach(QObject * obj, o->children()) { if(obj->property("requiredField").toBool()) // Check widget { if( (obj->inherits("QLineEdit") && obj->property("text").toString().isEmpty()) || (obj->inherits("QComboBox") && obj->property("currentText").toString().isEmpty()) || (obj->inherits("QComboBox") && obj->property("currentText").toString().toLower() == tr("- не вказано -")) || (obj->inherits("QDateEdit") && obj->property("date").toDate() <= limDate) || (obj->inherits("QGroupBox") && obj->property("objectName").toString() == "gbSex" && ui->rbUnknown->isChecked()) ) { ready_ &= false; QWidget * w = dynamic_cast<QWidget *>(obj); if(w) { QRect r(w->pos(), w->size()); p.drawRect(r.adjusted(-1, -1, 1, 1)); } } } } } } return QDialog::eventFilter(o, e);}
C++ (Qt) QWidget * w = dynamic_cast<QWidget *>(o); if(w && w->parentWidget()) { w->parentWidget()->update(QRect(w->pos(), w->size()).adjusted(-2, -2, 2, 2)); }