How do you get the current text contents of a QComboBox? How do you get the current text contents of a QComboBox? python python

How do you get the current text contents of a QComboBox?


You can convert the QString type to python string by just using the strfunction. Assuming you are not using any Unicode characters you can get a pythonstring as below:

text = str(combobox1.currentText())

If you are using any unicode characters, you can do:

text = unicode(combobox1.currentText())


PyQt4 can be forced to use a new API in which QString is automatically converted to and from a Python object:

import sipsip.setapi('QString', 2)

With this API, QtCore.QString class is no longer available and self.ui.comboBox.currentText() will return a Python string or unicode object.

See Selecting Incompatible APIs from the doc.


Getting the Text of ComboBox when the item is changed

     self.ui.comboBox.activated.connect(self.pass_Net_Adap)  def pass_Net_Adap(self):      print str(self.ui.comboBox.currentText())