python |
您所在的位置:网站首页 › 表格中添加下拉框选项在哪 › python |
参考:https://zhuanlan.zhihu.com/p/138386185 https://developer.aliyun.com/article/1314474 一、组合框控件ComboBoxComboBox的功能是从一个列表中一次只能选取或输入一个选项,其主要特点是具有带向下箭头的方框。在程序执行时,按下此按钮就会下拉出一个列表框供用户选择项目 属性说明Items表示该组合框中所包含项的集合SelectedItem获取或设置当前组合框中选定项的索引SelectedText获取或设置当前组合框中选定项的文本Sorted指示是否对组合框中的项进行排序addItem添加一个下拉选项addItems添加多个下拉选项currentIndex返回当前的下拉选项索引currentText返回当前下拉选项文本count返回下拉列表框中全部选项的个数removeItem删除选项clear清空所有选项insertItem将选项添加到指定的index位置setCurrentIndex显示指定index位置的选项【提示】在 qt designer 中 可以添加下拉框选择内容 self.ui.comboBox.addItem("苹果") # 添加单个选项 self.ui.comboBox.addItems(["葡萄","香蕉","西瓜"]) # 添加多个选项self.comboBox.activated.connect(self.getText()) # 当用户在组合下拉框中选中一个条目时发射此信号,索引作为参数传递 self.comboBox.currentIndexChanged.connect(self.box_result) # 索引变化时触发 绑定槽函数 self.comboBox.currentTextChanged.connect(self.box_result) # 文本变化时触发 self.comboBox.highlighted.connect(self.box_result) # 当用户高亮(光标移入或键盘选择)了弹出菜单中的某一条目时发射此信号 self.comboBox.textActivated.connect(self.box_result) # 当用户选择了条目之一时,发射此信号并将文本作为参数传递 self.comboBox.textHighlighted.connect(self.box_result) # 当用户高亮了弹出菜单中的某一条目时发射此信号
QInputDialog.getItem:选择选项的下拉列表 QInputDialog.getText:获取输入的文本内容 QInputDialog.getInt:获取输入数字的计时器 import sys from PyQt5.QtWidgets import * from PyQt5.QtCore import * from PyQt5.QtGui import * class QInputDialogDemo(QWidget): def __init__(self): super(QInputDialogDemo, self).__init__() self.initUI() def initUI(self): self.setWindowTitle("输入对话框") layout = QFormLayout() self.button1 = QPushButton("获取列表中的选项") self.button1.clicked.connect(self.getItem) self.lineEdit1 = QLineEdit() layout.addRow(self.button1, self.lineEdit1) self.button2 = QPushButton("获取字符串") self.button2.clicked.connect(self.getText) self.lineEdit2 = QLineEdit() layout.addRow(self.button2, self.lineEdit2) self.button3 = QPushButton("获取整数") self.button3.clicked.connect(self.getInt) self.lineEdit3 = QLineEdit() layout.addRow(self.button3, self.lineEdit3) self.setLayout(layout) def getItem(self): items = ('C', 'C++', 'Ruby', 'Python', 'Java') # 返回两个值,第一个item代表用户选择的值,ok代表用户是否按下了取消 item, ok = QInputDialog.getItem(self, "请选择编程语言", "语言列表", items) if ok and item: self.lineEdit1.setText(item) def getText(self): text, ok = QInputDialog.getText(self, "文本输入框", "输入姓名") if ok and text: self.lineEdit2.setText(text) def getInt(self): num, ok = QInputDialog.getInt(self, "整数输入框", "输入数字") if ok and num: self.lineEdit3.setText(str(num)) if __name__ == '__main__': app = QApplication(sys.argv) main = QInputDialogDemo() main.show() sys.exit(app.exec_()) |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |