Qt5 GUI How To Create QRadioButton

In this Qt5 GUI article iam going to show you How To Create QRadioButton.

 

Before starting our main topic , check Qt5 C++ GUI Development Articles with videos training and source codes

 

1: Qt5 C++ Introduction And Installation

2: Qt5 C++ First Console Application 

3: Qt5 C++ First GUI Application 

4: Qt5 C++ Signal And Slots Introduction

5: Qt5 C++ Layout Management 

6: Qt5 C++ Creating Qt Style Sheets

7: Qt5 C++ Creating QPushButton

8: How To Create QCheckBox in Qt5

A QRadioButton is an option button that can be switched on (checked) or off (unchecked). Radio buttons typically present the user with

a “one of many” choice. In a group of radio buttons, only one radio button at a time can be checked; if the user selects another button,

the previously selected button is switched off.

Radio buttons are autoExclusive by default. If auto-exclusive is enabled, radio buttons that belong to the same parent widget

behave as if they were part of the same exclusive button group. If you need multiple exclusive button groups for radio buttons

that belong to the same parent widget, put them into a QButtonGroup.

Just like QPushButton, a radio button displays text, and optionally a small icon. The icon is set with setIcon(). The text can be set

in the constructor or with setText(). A shortcut key can be specified by preceding the preferred character

with an ampersand in the text. For example:

 

 

So first of all you need to create a New Project in Qt5 C++ framework.

 

After that open your dialog.ui and we are going to give a simple design.

basically we need three QRadioButton with QPushButton, also we need a QLineEdit, you can give also your layouts for your widgets.

Qt5 QRadioButton
Qt5 QRadioButton

 

 

OK now after design it is time to do some coding in C++ , first open your dialog.cpp file

So for right now by default our QRadioButton is not checked, but if you want checked by default you need add this code in the constructor of

you dialog.cpp file.

 

After adding the dialog.cpp will look like this

 

 

So now right click on your QPushButton, after that choose Go To Slot and from the dialog choose clicked() signal.

and it will open your dialog.cpp with on_pushButton_clicked() signal.

after that write this code on that method.

 

Also your dialog.cpp will look like this at the end

 

 

OK now run the project and this will be the result

Qt5 GUI How To Create QRadioButton
Qt5 GUI How To Create QRadioButton

 

 

 

Also you can watch the complete video for this article

Subscribe and Get Free Video Courses & Articles in your Email

 

Codeloop
Share via
Copy link
Powered by Social Snap
×