简体   繁体   English

如何在 PyQt4 中创建自动完成 combobox?

[英]How to create autocomplete combobox in PyQt4?

How to create autocomplete combobox in PyQt4?如何在 PyQt4 中创建自动完成 combobox?

Example what I want:例如我想要的:

http://jqueryui.com/autocomplete/#combobox http://jqueryui.com/autocomplete/#combobox

To get the same behaviour as in the example, you will need to change the completion mode of the completer for the combobox.要获得与示例中相同的行为,您需要更改 combobox 的完成程序的完成模式

By default, the completion mode is inline (ie just selected text, with no alternatives).默认情况下,完成模式是内联的(即只选择文本,没有其他选择)。 To get the drop-down list of possible alternatives, do:要获取可能的替代方案的下拉列表,请执行以下操作:

    combobox.completer().setCompletionMode(QtGui.QCompleter.PopupCompletion)

combobox.setEditable(True) combobox.completer().setCompletionMode(QtGui.QCompleter.PopupCompletion) combobox.setInsertPolicy(QComboBox.NoInsert)

First line: autocompletion is only available for an editable combobox.第一行:自动完成功能仅适用于可编辑的 combobox。

Second line: sets required behavior for autocomplete method第二行:设置自动完成方法所需的行为

Last line: prevents the user to add items to the list (to better match the example behavior you provided)最后一行:阻止用户向列表中添加项目(以更好地匹配您提供的示例行为)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM