这是我的 Qlineedit Completer 示例程序。在自动建议之后,我想在我写的行编辑中将文本显示为项目的开始completer.activated.connect(lambda: QTimer.singleShot(0, lambda: edit.home(False)))
。它工作正常,但我不想在乞讨时显示光标,并在自动建议后显示光标。
下面是我的代码:
import sys
from PyQt4.QtCore import Qt,QTimer
from PyQt4.QtGui import QApplication, QCompleter, QLineEdit, QStringListModel
def get_data(model):
model.setStringList(["completionProgramxxxxxxxxxxxxxxx", "completionProgramyyyyyy","truthordisabled", "storecredit", "iamhere"])
if __name__ == "__main__":
app = QApplication(sys.argv)
edit = QLineEdit()
completer = QCompleter()
edit.setCompleter(completer)
completer.activated.connect(lambda: QTimer.singleShot(0, lambda: edit.home(False)))
model = QStringListModel()
completer.setModel(model)
get_data(model)
edit.show()
sys.exit(app.exec_())
我得到了这样的图像: