Radio Button Widget

The design for our user interface requires the use of radio buttons to select the appropriate crop type.

Main window design

Layout representation

Radio buttons are created by instantiating QRadioButton(). However, normally when using radio buttons you want to make it clear which radio buttons belong to a particular group and it is possible you may have multiple groups of radio buttons on your interface. For example, in another project you might give the option to select male or female and to select an specific age range.

In our example the final user-interface can be seen in the screenshot below. Notice the grey area surrounding the radio buttons and the instruction that is present just above the radio buttons. This shows the grouping of the buttons clearly.

Final crop selection interface

Because we might want to have multiple groups of radio buttons in future we are going to create a class which will enable us to easily create groups of radio buttons from a given list of text labels for each button. This means that if you ever need radio buttons again in the future you can just reuse this class.

The class definition will be:

RadioButtonWidget class definition

The video below demonstrates how to write the necessary code for this class.


Task 2a

Use the above video to help you create the radio button widget class.