PDA

View Full Version : Triggering the completer codewise



Sytse
2nd March 2016, 14:43
Hi,

For 2 days I am stuggling with de completer in PYQT. I expect the solution to be quite simple but, can't figure it out.

I want to use the completer to show suggestions in a Popup screen under a QLineEdit. If I type in my QLineEdit everything works great, but if I fill the QLineEdit with a command (I use an on screen keyboard) the popup is not displayed.

Just to illustrate I got the problem caught in a small sample program, if I type in de QLineEdit it's OK, If I press the Button it doesn't do anything.....

Regards,
Sytse




import sys
from PyQt4.QtGui import QApplication, QCompleter, QLineEdit, QStringListModel, QPushButton

def handleButton(model):
edit.setText('co')

def get_data(model):
model.setStringList(["completion", "data", "goes", "here"])

if __name__ == "__main__":

app = QApplication(sys.argv)
edit = QLineEdit()
completer = QCompleter()
edit.setCompleter(completer)

model = QStringListModel()
completer.setModel(model)
get_data(model)

edit.textChanged.connect(completer.setCompletionPr efix)

app.button = QPushButton('Test')
app.button.clicked.connect(handleButton)

edit.show()
app.button.show()
sys.exit(app.exec_())