search

Home  >  Q&A  >  body text

python - How does PyQt4 determine the currently selected item in the QComboBox list

question:

用pyqt4+Qdesigner编写了一个操作含有多个表单的excel工具,将所有表单名添加到QComoboBox的下拉选项中。现在想选中一个表单名后对当前表单操作,但是写好了好久没写出(初次接触pyqt)。
我的想法是选中当前列表中的表明后,输入数据,点击录入触发事件,事件中中添加一个判断当前是选中了哪个表单。但是现在不知道怎么判断当前表单,求助。

This is the ui interface:

Events triggered after clicking the input button:

The following is the py code corresponding to QComboBox generated using pyuic:

def setupUi(self, MainWindow):
    self.sheet_name = QtGui.QComboBox(self.centralwidget)
    self.sheet_name.setGeometry(QtCore.QRect(20, 30, 121, 22))
    self.sheet_name.setObjectName(_fromUtf8("sheet_name"))
    self.sheet_name.addItem(_fromUtf8(""))
    self.sheet_name.addItem(_fromUtf8(""))
    
  def retranslateUi(self, MainWindow):
       self.sheet_name.setItemText(0, _translate("MainWindow", "1", None))
    self.sheet_name.setItemText(1, _translate("MainWindow", "2", None))
巴扎黑巴扎黑2755 days ago714

reply all(1)I'll reply

  • ringa_lee

    ringa_lee2017-05-18 10:55:34

    str(self.sheet_name.currentText())

    reply
    0
  • Cancelreply