Qt5 GUI Development How To Create ComboBox

In this Qt5 GUI Development article iam going to show you To Create ComboBox

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

9: Qt5 GUI How To Create QRadioButton

 

 

 

QComboBox provides a means of presenting a list of options to the user in a way that takes up the minimum amount of screen space.

A combobox is a selection widget that displays the current item, and can pop up a list of selectable items. A combobox may be editable,

allowing the user to modify each item in the list.

 

 

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 to add a combobox in our design.

There are two ways that you can add items to combobox, the first way is by design. you need to right click on combobox

and after that choose Edit Items, in the dialog you can add your items like this.

Qt5 ComboBox Example
Qt5 ComboBox Example

 

After that run your project and this will be the result

Qt5 GUI Development How To Create ComboBox
Qt5 GUI Development How To Create ComboBox

 

 

OK now the second way is by coding in C++ language, open your dialog.cpp and in the constructor add these line of codes .

 

And dialog.cpp will look like this

 

 

After ruining the project the result will be the same

Qt5 GUI How To Create ComboBox

 

Now it is time to implement a simple signal and slot mechanism to our project, for this you need to add

a QPushButton with a QLabel in your design and remove the text of label .

so after that right click on the QPushButton and select Go To Slot and clicked().

 

add this line of code

 

After adding dialog.cpp will look like this

 

 

Run the complete project and this will be the result
Qt5 Combobox Items
Qt5 Combobox Items

 

 

 

Also you can watch the complete video tutorial for this article

Subscribe and Get Free Video Courses & Articles in your Email

 

Codeloop
Share via
Copy link
Powered by Social Snap
×