PyQt设置一行QComboBox的启用属性 [英] PyQt set enabled property of a row of QComboBox

查看:62
本文介绍了PyQt设置一行QComboBox的启用属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置 QComboBox 中一行的 enabled 属性?我希望它有一些禁用和一些启用的行.

How can I set the enabled property of a row of a QComboBox? I want it to have some disabled and some enabled rows.

推荐答案

这是一个 QComboBox 的工作示例,其中第 1 项和第 4 项(在列表 disable 中指定)被禁用.我使用了 this 示例.另请参阅 setData 方法的文档.

Here is a working example of a QComboBox, where items 1 and 4 (as specified in the list disable) are disabled. I used this example. See also the documentation for the setData method.

from PyQt4 import QtCore, QtGui
import sys

class Foo(QtGui.QMainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)

        items = ['foo', 'bar', 'yib','nuz', 'pip', 'rof']
        cb = QtGui.QComboBox(self)
        for i in items:
            cb.addItem(i)

        disable = [1,4]
        for i in disable:
            j = cb.model().index(i,0)
            cb.model().setData(j, QtCore.QVariant(0), QtCore.Qt.UserRole-1)

if __name__ == "__main__":
    app = QtGui.QApplication([])
    foobar = Foo()
    foobar.show()
    sys.exit(app.exec_())

这篇关于PyQt设置一行QComboBox的启用属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆