def validateForm(self): """ Validate the users form. If there are any errors report them to the user. @refactor: Should really just return a bool and let the caller handle what happens next. We should also consider using QValidator for validation. """ controls = self.binder.mandatory_group.unchanged() haserrors = len(controls) > 0 if haserrors: dlg = QDialog() dlg.setWindowFlags( Qt.Tool | Qt.WindowTitleHint ) ui = Ui_Dialog() ui.setupUi(dlg) for control in controls: label = self.dialog.findChild(QLabel, control.objectName() + "_label") if not label is None: name = label.text() elif isinstance(control, QCheckBox): name = control.text() elif isinstance(control, QGroupBox): name = control.title() name += " is mandatory" item = QListWidgetItem(name) item.setBackground(QBrush(QColor.fromRgb(255,221,48,150))) ui.errorList.addItem(item) dlg.exec_() else: self.dialogAccept()
def validateForm(self): controls = self.binder.mandatory_group.unchanged() haserrors = len(controls) > 0 if haserrors: dlg = QDialog() dlg.setWindowFlags( Qt.Tool | Qt.WindowTitleHint ) ui = Ui_Dialog() ui.setupUi(dlg) for control in controls: label = self.dialog.findChild(QLabel, control.objectName() + "_label") if not label is None: name = label.text() elif isinstance(control, QCheckBox): name = control.text() elif isinstance(control, QGroupBox): name = control.title() name += " is mandatory" item = QListWidgetItem(name) item.setBackground(QBrush(QColor.fromRgb(255,221,48,150))) ui.errorList.addItem(item) dlg.exec_() else: self.dialogAccept()