Hello,
can you give a LFE aka a little functiunal example ?

C.


Greg Smith a écrit :

Hey Everyone,

I’m trying to get a LineEdit I have in a tool I am writing to have the ability to auto complete the user’s entry based on what they have typed. From the sounds of it, QCompleter is exactly what I am after and they work on QLineEdit widgets. However I am having difficulty getting it to work, so I was wondering if I could share what I am trying to do and see if I am doing anything wrong or not doing something that I should be in order to get it to work.

So here’s an abridged example of what I am doing.

--------------------------------------------------------------------------------------------------------------------

From PyQt4 import QtCore, QtGui, uic

defaultList = [‘foo’, ‘bar’, ‘alpha’, ‘beta’, ‘ceti’, ‘delta’]

completerList = QtCore.QStringList()

for i in defaultList:

completerList.append(QtCore.QString(i))

#defining my QDialog

class MyPyQtTool(QtGui.QDialog):

def __init__(self):

QtGui.QDialog.__init__(self)

self.ui = uic.loadUi (‘C:\\myUiFile.ui’)

lineEditCompleter = QtGui.QCompleter(completerList)

lineEditCompleter.setCompletionMode(QtGui.QCompleter.InlineCompletion)

lineEditCompleter.setCaseSensitivity(QtCore.Qt.CaseInsensitive)

self.ui.myLineEdit_widget.setCompleter(lineEditCompleter)

#... defining other tool logic

# I also have the list being modified in another method based off of user’s selection.

def onMyComboBoxActivated(self)

# code here where a string list is created from a mysql db query based on combo box selection.

for i in dbQryList:

completerList.append(QtCore.QString(i))

lineEditCompleter = QtGui.QCompleter(completerList)

lineEditCompleter.setCompletionMode(QtGui.QCompleter.InlineCompletion)

lineEditCompleter.setCaseSensitivity(QtCore.Qt.CaseInsensitive)

self.ui.myLineEdit_widget.setCompleter(lineEditCompleter)

app = QtGui.QApplication(sys.argv)

dialog = MyPyQtTool()

dialog.ui.show()

app.exec_()

-----------------------------------------------------------------------------------------------------------------------

This may not be the cleanest way of doing what I want but from the example shown in the class reference web page, this should be sound.

However when I try to test it, I get no completion what so ever. No errors are thrown so I am not exactly sure what I am doing wrong.

Is there another method that needs to be executed before it should work?

Any help would be truly appreciated!

Thanks,

Greg



_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to