[PyQt] Qcompleter,dateEdit popup questions.

Igor Prischepoff igor at tyumbit.ru
Wed Feb 6 06:53:14 GMT 2008


Hello,everybody!
I'm new to PyQt and in process of 
converting my application from wxPython to PyQt.

I'd like to ask couple of question about nice QCompleter class in Qt and
PyQt.

Question #1:
How can I build my own custom completer which completes on any char in the
item word?
It seems that default Qcompleter completes only if my items starts with
letters that I've started typing.
For example: here is my abstract model data:

Item10
Item110
Item20
Item220

If I type for example 'm10' then completer should provide only 2 matches
Item10 Item110 because 'm10' chars is found only in this two items.

I've read documentation about QCompleter in Qt docs but can not find a clue
about methods used by Qcompleter when deciding which item from model is
matched to my typed word.

I think I should inherit from QCompleter something like this:

class MyCompleter(QCompleter):
    def __init__(self, parent=None):
        super(MyCompleter, self).__init__(parent)
        self.model = MyCompletionModel()
        self.setModel(self.model)
        self.setCompletionColumn(0)

Now the question is : which method should I override in order to intercept
QCompleter decision about which item from model is fit for currently entered
text?

Is there something like this? :
    def complete_decison_method(self,item):
        prefix = self.completionPrefix() # Get typed text which shoud be
completed or matched.
        if str(item).find(prefix) == -1 :
	# no - this item don't match entered text, don't show it in popup
	return False
        else
            # yes! this item matches somewhere with prefix - it's valid to
complete!
            return True

Can someone provide hint or url maybe?
I've read http://doc.trolltech.com/4.2/qcompleter.html but don't find enough
info to answer my question.

Question #2:
 I have a dateEdit widget with calendarPopup = true.
When calendar chooser is shown in popup - week is started from Sunday.
Can I have a dateEdit widget with popup where week is started from Monday?
My locale is correct I think, so in calendar popup I am seen  russian
letters, so problem is not in locale setup I think.

My platform: Python 2.5, PyQt 4.3.3 GPL , winXP.

---
igor at tyumbit.ru



More information about the PyQt mailing list