pyqt5 配置向导:PyQt5-8.comboBox功能初体验
pyqt5 配置向导:PyQt5-8.comboBox功能初体验运行演示5 从combo Box2中自动获取选中candy:运行演示4 从combo Box中删除选中anan:控件使用运行演示2 再次添加candy到两个comboBox中,如下图:运行演示3 从combo Box中选中anan,获取并赋值给lineEdit中:
千呼万唤使出来,抽个空更新一下PyQt5系列。
本期练习comboBox。
UI设计如下 ctrl R演示功能为预运行如下:
运行演示1 添加anan到两个comboBox中,如下图:
控件使用
运行演示2 再次添加candy到两个comboBox中,如下图:
运行演示3 从combo Box中选中anan,获取并赋值给lineEdit中:
运行演示4 从combo Box中删除选中anan:
运行演示5 从combo Box2中自动获取选中candy:
选中candy后,将自动复制给自动选中lineEdit.
附代码:
class MainWindow(QMainWindow Ui_QTtest):
def __init__(self parent=None):
super(MainWindow self).__init__(parent)
self.setupUi(self)
self.comboBox_2.currentIndexChanged.connect(self.auto_get)#自动获取combobox选中内容
def auto_get(self):
self.lineEdit_4.setText(self.comboBox_2.currentText())
@pyqtSlot()
def on_pushButton_clicked(self):
filedir = self.openfile()[0]
self.data = pd.read_excel(filedir)
self.lineEdit.setText(filedir)
self.model.setDataFrame(self.data)
@pyqtSlot()
def on_pushButton_2_clicked(self):
getLineEdit1 = self.lineEdit_2.text()
self.comboBox.addItem(getLineEdit1)
self.comboBox_2.addItem(getLineEdit1)#addItems 从list里添加多个选项
@pyqtSlot()
def on_pushButton_3_clicked(self):
getComboBoxContent = self.comboBox.currentText()
self.lineEdit_3.setText(getComboBoxContent)
@pyqtSlot()
def on_pushButton_4_clicked(self):
index = self.comboBox.currentIndex()
self.comboBox.removeItem(index)