[PyQt] auto-completing combo box with table view

Horst Herb subscriptions at gnumed.net
Wed Nov 28 11:16:09 GMT 2007


On Wednesday 28 November 2007, Andreas Pakulat wrote:
> That model provides data, no matter wether the index is valid or not or
> the role matches Qt.DisplayRole. That means you break the contract
> between model and view.

It is just a dummy to deliver some data to test the widget - should do that 
trick

> > class MyCompleter(QCompleter):
> >     def __init__(self, parent=None):
> >         super(MyCompleter, self).__init__(parent)
> >         model = MyCompletionModel()
>
> Thats another bad idea, you don't keep a reference to the model so it
> will disappear as soon as __init__ is done.

Really:
model = MyCompletionModel()
self.setModel(model)

I would have thought that if I pass the model to the completer via setModel, 
it keep the reference alive

> > class AutoCompletionTest(QDialog):
> >     def __init__(self, parent=None):
> >         super(AutoCompletionTest, self).__init__(parent)
> >         self.combo = QComboBox()
> >         self.combo.setEditable(True)
> >         completer = MyCompleter()
>
> Same thing here.
>
> >         self.combo.setCompleter(completer)
> >         layout = QVBoxLayout()
> >         layout.addWidget(self.combo)
> >         self.setLayout(layout)
>
> I'm not 100% sure about the layout, it might be re-parented to self and
> you don't need to keep a reference to it yourself. I guess if your gui
> show up at least your fine here.

It shows up fine, just doesn't autocomplete - the code I posted was the 
smallest example I could come up with to demonsrate my problem

Horst
-- 
In existing States a fresh law is looked upon as a remedy for evil. Instead of 
themselves altering what is bad, people begin by demanding a law to alter it.

    Peter Kropotkin, Law and Authority



More information about the PyQt mailing list