zoukankan      html  css  js  c++  java
  • 下拉列表框-QComboBox

    QComboBox是一个集按钮和下拉选项于一体的控件,也被称为下拉列表框。

    QComboBox类中的常用方法:

      addItem()    添加一个下拉选项

      addtems()     从列表中添加下拉选项

      Clear()       删除下拉选项集合中的所有选项

      count()      返回下拉选项集合中的数目

      currentText()  返回选择选项的文本

      itemText()       获取索引为i的item的选项文本

      currentIndex()   返回选中项的索引

      setItemText()        改变序号为index项的文本

    QComboBox类中的常用信号

      Activated    当用户选中一个下拉选项时发射该信号

      currentIndexChanged  当下拉选项的索引发生改变时发射该信号

      highlighted     当选中一个已经选中的下拉选项时,发射该信号

    案例17  QComboBox按钮的使用

    import sys
    from PyQt5.QtCore import Qt
    from PyQt5.QtWidgets import QWidget, QApplication, QCheckBox, QComboBox, QLabel, QVBoxLayout
    
    
    class ComboBoxDemo(QWidget):
        def __init__(self, parent=None):
            super().__init__(parent)
            self.setWindowTitle("ComboBox 例子")
            self.resize(300, 90)
            layout = QVBoxLayout()
            self.lb1 = QLabel("")
    
            self.cb = QComboBox()
            self.cb.addItem("C")
            self.cb.addItem("C++")
            self.cb.addItems(["Java", "C#", "Python"])
            self.cb.currentIndexChanged.connect(self.selectionchange)
            layout.addWidget(self.cb)
            layout.addWidget(self.lb1)
            self.setLayout(layout)
    
        def selectionchange(self, i):
            self.lb1.setText(self.cb.currentText())
            print("Items in the list are :")
            for count in range(self.cb.count()):
                print("item" + str(count) + "=" + self.cb.itemText(count))
                print("Current index", i, "selection changed", self.cb.currentText())
    
    
    if __name__ == "__main__":
        app = QApplication(sys.argv)
        comboboxdemo = ComboBoxDemo()
        comboboxdemo.show()
        sys.exit(app.exec_())
  • 相关阅读:
    Helvetic Coding Contest 2016 online mirror D1
    Helvetic Coding Contest 2016 online mirror C1
    Helvetic Coding Contest 2016 online mirror A1
    Educational Codeforces Round 13 C
    Educational Codeforces Round 13 B
    Educational Codeforces Round 13 A
    2016计蒜之道初赛第四场A
    帆软出品: 7点搞定制药企业数据分析系统开发需求
    制药企业BI系统方案整体设计分享
    Ubuntu ROS Arduino Gazebo学习镜像iso说明(indigo版)
  • 原文地址:https://www.cnblogs.com/lynsha/p/13408764.html
Copyright © 2011-2022 走看看