I
I
Issue2019-09-14 23:36:45
Python
Issue, 2019-09-14 23:36:45

How to get the selected value of a QComboBox in Python?

Hello. Can you please explain to me how accessing a QComboBox and getting the selected value from it works?

from PyQt5 import QtCore, QtGui, QtWidgets
import sys
from gui import Ui_MainWindow # Здесь подключается UI формы

app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()

comboValue = 0

def installer():
- - - - # Здесь я хочу проверить выбранное значение ui.comboBox и записать в переменную comboValue = 1
- - - - print(comboValue)

ui.pushButton_search.clicked.connect( installer ) # Нажатие на кнопку установить

I have been trying to understand how these signals work for a long time and I don’t understand, please give a simple example. Thank you in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Zhuravlev, 2019-09-27
@paulenot

QComboBox has wonderful methods: ui.comboBox.currentText()ui.comboBox.currentData(), which return the text or data associated with the given value, respectively. No signals are needed to use them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question