PyCoder PyCoder - 3 months ago 52
Python Question

Python PyQt QLineEdit to Search bar

am trying to build translator and put a search bar in it .with QLineEdit
and what i want is auto complet the word .
..
i tried this . but this code is not working , i'm talking about SearchBar function . but the rest of the code is working with the rest program just fine . but the SearchBar function not working . and not completing what i type in LineEdit

from PyQt4 import QtGui,QtCore
import sys
from MainWin import Ui_MainWindow
import sqlite3

conn = sqlite3.connect('DictDB.db')
cors = conn.cursor()


class MainApp(QtGui.QMainWindow,Ui_MainWindow):
def __init__(self):
super(MainApp,self).__init__()

self.setupUi(self)
self.showMaximized()

cors.execute("SELECT * FROM DictContents")
for raw in cors.fetchall():
self.TextBrowserAra.append(raw[0])
self.TextBrowserGer.append(raw[1])
self.SearchBar(raw[0].strip(),raw[1].strip())


def SearchBar(self,keys,values):
mydict = {}
AraKey = mydict[0]=[keys]
GerKey = mydict[1]=[values]
Model = QtGui.QStringListModel()
ModAra = Model.setStringList(AraKey)
ModGer = Model.setStringList(GerKey)
completer = QtGui.QCompleter()
CompAra = completer.setModel(ModAra)
ComGer = completer.setModel(ModGer)
self.LineEditAra.setCompleter(CompAra)
self.LineEditGer.setCompleter(ComGer)

Answer

The function setModel() and setCompleter() are void, return no value.

Doc: setModel setCompleter

You can write like this:

    AraKey = ['a','ab','abc']
    ModAra = QtGui.QStringListModel()
    ModAra.setStringList(AraKey)
    ComAra = QtGui.QCompleter()
    ComAra.setModel(ModAra)
    self.LineEditAra.setCompleter(ComAra)

I hava tried this, and it really works.