PyQt Basic Widgets PyQt QComboBox Widget - PyQt

What is PyQt QComboBox Widget?

A QComboBox item gives a dropdown list of objects to choose from. It takes minimum screen area at the form required to show only the currently selected item.

A combo field can be set to be editable; it may also save pixmap objects. the following methods are generally used −

Given underneath are the most usually used methods of QComboBox.

S.No.

Methods & Description

1

addItem()

Adds string to collection

2

addItems()

Adds items in a list object

3

Clear()

Deletes all items in the collection

4

count()

Retrieves number of items in the collection

5

currentText()

Retrieves the text of currently selected item

6

itemText()

Displays text belonging to specific index

7

currentIndex()

Returns index of selected item

8

setItemText()

Changes text of specified index

QComboBox signals

S.No.

Methods & Description

1

activated()

When the user chooses an item

2

currentIndexChanged()

Whenever the current index is changed either by the user or programmatically

3

highlighted()

When an item in the list is highlighted

Example

Let us see how a few features of QComboBox widget are carried out in the following example.

Objects are introduced within the collection individually through addItem() technique or items in a list object through addItems() technique.

QComboBox item emits currentIndexChanged() signal. it is related to selectionchange() technique.

Objects in a combo container are listed the usage of itemText() technique for every object. Label belonging to the presently selected item is accessed through currentText() technique.

The entire code is as follows −

The above code produces the following output –

PyQt - QComboBox Widget

Items in the list are –

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

PyQt Topics