QCombobox下拉菜单自动补全的一些特性:
1.QCombobox.setEditable(True) 这个必须设置为True
2.QCombobox下拉菜单自动补全只会补全item_list里(item_list是列表)
代码:QCombobox.setCompleter(QCompleter(item_list)
QCombobox下拉菜单自动补全设置就完成了
开启了QCombobox可编辑后,在combobox输入任何内容都会自动添加到下拉选项中
如果不想破坏下拉选项的原有的选项,可以这么做:
QCombobox.setCompleter(QCompleter(item_list)
def combobox_activted():
if not QCombobox.currentText() in item_list:
QCombobox.clear()
QCombobox.setItems(item_list)
QCombobox.setCurrentIndex(-1)
QCombobox.activted.connect(combobox_activted)