pyQT5中ComboBox的用法
常用的方法
1、添加下拉选项
#添加一个下拉选项
self.comboBox.addItem("默认文本")
#从列表中添加下拉选项
self.comboBox.addItems(["文本1", "文本2", "文本3"])
2、设置显示项目
self.comboBox.setCurrentIndex(2)
3、获取选项中的索引
self.comboBox.currentIndex()
4、获取选中项的文本
self.comboBox.currentText()
常用的信号
1、activated
在用户选中一个下拉选项时发射
2、currentIndexChanged
在下拉选项索引发生改变时发射
例程
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'ex_combox.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
clas