PDA

View Full Version : Best way of defining mandatory fields?



adzh
8th July 2016, 22:34
What is best way of defining mandatory fields inside QWidget/MainWindow view?
I want to make few fields (ComboBoxes, LineEdit, and few SpinBoxes) mandatory by making them highlight when default values are selected on an event.

ChrisW67
8th July 2016, 22:55
You should indicate which widgets are mandatory inputs in some way. Often this is with an asterisk in the label, e.g. "Name*:", or by setting the widget background or border to a different colour.

By "on an event" I assume you mean when they push a button or select a menu item to trigger some process using the inputs. In that case, the slot that is triggered should check that all mandatory inputs have a suitable value. If they do then run the process, if not then call setFocus() on the input widget that has an unacceptable value, issue a message, and do not run the process.

Another approach would be to monitor the changed signals of the manadatory fields. When any field changes check all the fields and if all are acceptable enable the button to trigger the process, disable it otherwise.