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

前端 未结 4 1776
误落风尘
误落风尘 2020-12-05 06:40

Using pyqt4 and python 2.6, I am using a qcombobox to provide a list of options. I am having problems with using the selected option. I have been able to use a signal to tri

相关标签:
4条回答
  • 2020-12-05 07:12

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

    import sip
    sip.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.

    0 讨论(0)
  • 2020-12-05 07:19

    If you want the text value of a QString object you can use the __str__ property, like this:

    >>> a = QtCore.QString("Happy Happy, Joy Joy!")
    >>> a
    PyQt4.QtCore.QString(u'Happy Happy, Joy Joy!')
    >>> a.__str__()
    u'Happy Happy, Joy Joy!'
    

    Hope that helps.

    0 讨论(0)
  • 2020-12-05 07:23

    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())
    
    0 讨论(0)
  • 2020-12-05 07:25

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

    text = str(combobox1.currentText())
    

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

    text = unicode(combobox1.currentText())
    
    0 讨论(0)
提交回复
热议问题