How do I get the current text from a QcomboBox with PyQt5 using a button?
Funny that this isn’t better documented. But basically I’m just trying to get the value of a dropdown QComboBox in PyQT5 when I click a button.
Currently, when I use the following code, it is only giving me the value after I select a value in the dropdown. I am new to PyQt.
![]()
3 Answers 3
![]()

![]()
I am not sure if I completely understood your question. You just want to get the text that is in the QComboBox when you click on the button? If that is the case then it’s pretty simple. First you need to get the current text in the QComboBox then put it in the QLineEdit . Your don’t need the to use a Signal here. So you can remove the following line:
And update your change_text method like this.
Not the answer you're looking for? Browse other questions tagged python pyqt5 or ask your own question.
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
Site design / logo © 2022 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2022.6.10.42345
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
QComboBox¶


A 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.
Comboboxes can contain pixmaps as well as strings; the insertItem() and setItemText() functions are suitably overloaded. For editable comboboxes, the function clearEditText() is provided, to clear the displayed string without changing the combobox’s contents.
There are three signals emitted if the current item of a combobox changes, currentIndexChanged() , currentTextChanged() and activated() . currentIndexChanged() and currentTextChanged() are always emitted regardless if the change was done programmatically or by user interaction, while activated() is only emitted when the change is caused by user interaction. The highlighted() signal is emitted when the user highlights an item in the combobox popup list. All three signals exist in two versions, one with a QString argument and one with an int argument. If the user selects or highlights a pixmap, only the int signals are emitted. Whenever the text of an editable combobox is changed the editTextChanged() signal is emitted.
When the user enters a new string in an editable combobox, the widget may or may not insert it, and it can insert it in several locations. The default policy is InsertAtBottom but you can change this using setInsertPolicy() .
It is possible to constrain the input to an editable combobox using QValidator ; see setValidator() . By default, any input is accepted.
A combobox can be populated using the insert functions, insertItem() and insertItems() for example. Items can be changed with setItemText() . An item can be removed with removeItem() and all items can be removed with clear() . The text of the current item is returned by currentText() , and the text of a numbered item is returned with text(). The current item can be set with setCurrentIndex() . The number of items in the combobox is returned by count() ; the maximum number of items can be set with setMaxCount() . You can allow editing using setEditable() . For editable comboboxes you can set auto-completion using setCompleter() and whether or not the user can add duplicates is set with setDuplicatesEnabled() .
QComboBox uses the model/view framework for its popup list and to store its items. By default a QStandardItemModel stores the items and a QListView subclass displays the popuplist. You can access the model and view directly (with model() and view() ), but QComboBox also provides functions to set and get item data (e.g., setItemData() and itemText() ). You can also set a new model and view (with setModel() and setView() ). For the text and icon in the combobox label, the data in the model that has the DisplayRole and DecorationRole is used. Note that you cannot alter the SelectionMode of the view() , e.g., by using setSelectionMode() .
Constructs a combobox with the given parent , using the default model QStandardItemModel .
This enum specifies what the QComboBox should do when a new string is entered by the user.
PyQt5 — QComboBox Widget
A QComboBox object presents a dropdown list of items to select from. It takes minimum screen space on the form required to display only the currently selected item.
A Combo box can be set to be editable; it can also store pixmap objects. The following methods are commonly used −
Adds string to collection
Adds items in a list object
Deletes all items in the collection
Retrieves number of items in the collection
currentText()
Retrieves the text of currently selected item
Displays text belonging to specific index
currentIndex()
Returns index of selected item
setItemText()
Changes text of specified index
QComboBox Signals
The following methods are commonly used in QComboBox Signals −
When the user chooses an item
currentIndexChanged()
Whenever the current index is changed either by the user or programmatically
highlighted()
When an item in the list is highlighted
Example
Let us see how some features of QComboBox widget are implemented in the following example.
Items are added in the collection individually by addItem() method or items in a List object by addItems() method.
QComboBox object emits currentIndexChanged() signal. It is connected to selectionchange() method.
Items in a combo box are listed using itemText() method for each item. Label belonging to the currently chosen item is accessed by currentText() method.