Python Forum
[PyQt] Get Data from QComboBox
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] Get Data from QComboBox
#1
Good day to everyone!
How can I get value of QComboBox? Cause from currentText() I only get my first value. In the internet i found examples where value prints in the function, but I need to get value for the next function.
And is it possible at all?

Thanks in advance. Sorry for gramma.

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QComboBox, QPushButton


class Example(QWidget):

    def __init__(self):
        super().__init__()

        self.initUI()


    def initUI(self):
        lbl1 = QLabel('Example:', self)
        lbl1.move(15, 10)
        combo = QComboBox(self)
        combo.addItems(["11", "22", "33"])
        combo.move(70, 8)
        combo.activated[str].connect(self.onActivated)   # Reassign Qlabel
        currText = combo.currentText()  # But how to reassing currText



        self.lbl2 = QLabel('11', self)
        self.lbl2.move(15, 50)

        self.btn = QPushButton("go", self)
        self.btn.move(100, 50)
        self.btn.clicked.connect(lambda: self.doCalc(currText))


        self.setGeometry(300, 300, 200, 100)
        self.setWindowTitle("Application")
        self.show()



    def onActivated(self, text):
        self.lbl2.setText(text)
        self.lbl2.adjustSize()

    def doCalc(self, text):
        print("work", text)


if __name__ == '__main__':

    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] How do I display the DB table I will choose from the QComboBox in QTableWidget JokerSob 2 2,296 Aug-05-2021, 03:00 PM
Last Post: JokerSob
  [PyQt] display content from left to right in QComboBox or QLineEdit mart79 2 2,301 May-30-2020, 04:38 PM
Last Post: Axel_Erfurt
  QComboBox doesn't display selection as long as it has not lost the focus Meaulnes 3 3,227 May-07-2020, 03:42 PM
Last Post: Meaulnes
  QComboBox for PyQt code gvin47 3 2,090 Apr-22-2020, 04:01 PM
Last Post: gvin47
  [PyQt] PyQt4 dynamic QComboBox littleGreenDude 4 5,670 Jan-02-2019, 07:22 PM
Last Post: littleGreenDude
  [PyQt] How can I get special data from QComboBox()? Sophus 0 5,076 Jul-26-2017, 04:56 PM
Last Post: Sophus

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020