setCurrentIndex() 就可以通過索引設置當前內容爲items裏的某個值,從0開始。
例:“2"就代表"腳本管理”
currentText() 就可以獲取當前選擇的內容。
items = ["腳本錄製", "腳本回放", "腳本管理"]
self.comboBox = QtWidgets.QComboBox()
self.comboBox.addItems(items)
self.comboBox.setCurrentIndex(2) # 設置默認值
self.comboBox.currentText() # 獲得當前內容
運行效果圖:
喜歡的點個贊❤吧!