(E) Body mass indexΒΆ

Goal: I will learn to create a simple dialog using Qt Designer, and to understand the signals & slots mechanism of Qt.

Instructions: Create a new project: student/12/bmi/.

Create the new project according to to the instructions in the previous material sections.

Your task is to use Qt Designer to implement a dialog that looks like the figure below.

../../_images/bmi_tyhja.png

After the user has given their weight and height readings and clicked the Count button, the program counts the body mass index. After that the dialog will look, for example, like below.

../../_images/bmi_taytetty.png

On the right from the label BMI, there is another label, which is first empty but after clicking the Count button, it shows the body mass index. On the right from the label Info, there is a textBrowser component, to which will be printed one of the texts:

  • You are underweight.
  • You are overweight.
  • Your weight is normal.

Body mass index (BMI) can be counted from the formula:

\[BMI = \frac{mass[kg]}{(height[m])^{2}}\]

The lower bound of normal weight is 18.5 and the upper bound is 25.

Attention

Use the following object names for lineEdit widgets: weightLineEdit and heightLineEdit. For these widgets, use the signals editingFinished and textChanged. For buttons, use the object names: countButton and closeButton. For the label, in which you print the body mass index, use the object name resultLabel. For the textBrowser widget, in which you print the information about underweight, overweight, or normal weight, use the object name infoTextBrowser.

In the same way as in the Find dialog exercise, use the signal & slot mechanism to connect suitable actions for the widgets.

Tips for completing the assignment:

  • A good place to start is to construct the user interface.
  • Anyway, you can use similar steps to those described in the Find dialog exercise.

A+ presents the exercise submission form here.