我有內部的不同值的組合框:是,否QComboBox setCurrentIndex通過文本
我可以設置通過我從輸入接收值的組合框?我不想通過索引號來設置它。我也想盡量遠離if語句。
我已經試過這樣的事情:
self.UnlHE_Drop = QtWidgets.QComboBox(self.scrollAreaWidgetContents)
self.UnlHE_Drop.setObjectName("UnlHE_Drop")
self.UnlHE_Drop.addItem("")
self.UnlHE_Drop.setItemText(0, "")
self.UnlHE_Drop.addItem("")
self.UnlHE_Drop.addItem("")
def retranslateUi(self, VlS):
_translate = QtCore.QCoreApplication.translate
VlS.setWindowTitle(_translate("VlS", "Value"))
self.UnlHE_Drop.setItemText(1, _translate("VlS", "Yes"))
self.UnlHE_Drop.setItemText(2, _translate("VlS", "No"))
self.UnlHE_DropInfo = QInputDialog.getText(None, 'Answer:', 'Yes or No:')
self.UnlHE_Drop.setCurrentIndex(self.UnlHE_Drop.findText(self.UnlHE_DropInfo))
哪個返回'self.UnlHE_Drop.findText'函數? – eyllanesc
什麼是'UnlHE_Drop'? – eyllanesc
一般來說,解決方案似乎是正確的,除非用戶放置不合適的值。 – eyllanesc