FW: [PyQt] Using a QCompleter with a QLineEdit

Greg Smith gsmith at troublemakerstudios.com
Wed Jun 24 19:44:30 BST 2009


Here is a very simple test.
Just run it in a command shell, and be sure the .ui file lives in the same directory as the .py file.

Greg

-----Original Message-----
From: projetmbc [mailto:projetmbc at club-internet.fr] 
Sent: Wednesday, June 24, 2009 11:00 AM
To: Greg Smith
Cc: pyqt at riverbankcomputing.com
Subject: Re: [PyQt] Using a QCompleter with a QLineEdit

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
>




-------------- next part --------------
A non-text attachment was scrubbed...
Name: simpleTest.py
Type: application/octet-stream
Size: 1368 bytes
Desc: simpleTest.py
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20090624/d75b2e9d/simpleTest-0002.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: simpleTest.ui
Type: application/octet-stream
Size: 1321 bytes
Desc: simpleTest.ui
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20090624/d75b2e9d/simpleTest-0003.obj


More information about the PyQt mailing list