QComboBox用法小结

时间:2025-02-09 16:23:34

 fromComboBox = QComboBox() 添加一个 combobox


        (rates) 添加一个下拉选项

      (["%d years" % x for x in range(2, 26)]) 从序列中添加

         (10) #设置最大显示下列项 超过要使用滚动条拖拉

        (5) #设置最大下拉项 超过将不显示

        () #设置插入方式

      插入方式有:NoInsert,InsertAtTop,InsertAtCurrent,InsertAtBottom,InsertAfterCurrent

                      InsertBeforeCurrent,InsertAlphabetically

                      字面意思都好理解 最后一个是按字母表顺序插入

       QComboBox 发出一个currentIndexChanged(int) 的信号.

       QComboBox 得到当前项 currentIndex() + 1 #QComboBox 默认的currentIndex为 -1

       setCurrentIndex可以来设置当前的项

       QVariant QComboBox::itemData ( int index, int role = Qt::UserRole ) const 返回给定index处的数据

       ('dsfds') #返回 内容为dsfds的索引

       ()设置下拉列表要显示的可编辑内容

       QComboBox 得到当前项文本内容 currentText()

 

 

 

 

        fromSpinBox = QDoubleSpinBox()


        (0.01, 10000000.00)

       (" %d") #设置后缀 如显示 10.0%d

        ('#d') #设置前缀
        (1.00) 设置值

       QDoubleSpinBox 发出 valueChanged(double) 信号 有setValue(double)插槽

 

当QComboBox当前项发生变化时候,它会发出信号currentIndexChanged(int i),i是改变后当前项的下标,可以编写SLOT来处理


查看代码示例