各位高手好,我用PYQT寫了一個combobox,然後功能是只要切換選項就會把對應的SQL資料顯示到editline上,但是combobox好像只能對應一個參數,請問有辦法讓一個combobox對應多個參數或是怎樣寫可以達成一個combobox可以顯示出多個editline內容?
以下是我的程式碼
def __init__(self):
super(AddCoopWindow, self).__init__()
self.setupUi(self)
self.setWindowModality(Qt.ApplicationModal)
self.setWindowFlags(Qt.WindowCloseButtonHint)
self.setWindowTitle('新增資料')
self.add_book_pushButton.clicked.connect(self.add)
self.setWindowIcon(QIcon(APP_ICON))
self.add_book_pushButton.setProperty('class', 'Aqua')
self.setStyleSheet(SYS_STYLE)
self.hr_name_comboBox.currentIndexChanged.connect(self.hr_email)
self.hr_name() #自行新增函數要加入到__init__進行初始化
def hr_name(self):
db = DBHelp()
count_coop4hr, res_coop4hr = db.query_all_coop4hr(table_name='hr')
for row in res_coop4hr:
un, email, phone = row
self.hr_name_comboBox.addItem(un, email)
def hr_email(self):
self.hremail_lineEdit.setText(self.hr_name_comboBox.currentData()) #抱歉,原本的是這樣,自己在試的時候多加了self.hr_name
忘記補充,這是我另一邊的SQL程式碼
def query_all_coop4hr(self, table_name):
sql_coop4hr = 'select human_name,email,phone from hr'
count_coop4hr = self._cur.execute(sql_coop4hr)
res_coop4hr = self._cur.fetchall()
return count_coop4hr, res_coop4hr