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
def handleButton(model):
edit.setText('co')
def get_data(model):
model.setStringList(["completion", "data", "goes", "here"])
if __name__ == "__main__":
edit.setCompleter(completer)
completer.setModel(model)
get_data(model)
edit.textChanged.connect(completer.setCompletionPrefix)
app.button.clicked.connect(handleButton)
edit.show()
app.button.show()
sys.exit(app.exec_())
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.setCompletionPrefix)
app.button = QPushButton('Test')
app.button.clicked.connect(handleButton)
edit.show()
app.button.show()
sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode
Bookmarks