I have created a custom QCompleter class which displays all items in a popup that contain the typed word of a QLineEdit.
Right now all items are ordered alphabetically as you can see here:
I want the popup to display "dab" as the first suggestion if I type in "dab" and then the other items in alphabetical order.
I want this popup order:
- dab
- amendable
- decidable
- dividable
- guidable
- spendable
- ...
How can i achieve this?
This is the custom QCompleter class I'm using:
Code
class MyCompleter : public QCompleter
{
Q_OBJECT
public:
inline MyCompleter(const QStringList& words, QObject * parent) :
QCompleter(parent), m_list(words), m_model()
{
setModel(&m_model);
}
// Filter
inline void update(QString word)
{
// Include all items that contain "word".
QStringList filtered = m_list.filter(word, caseSensitivity());
m_model.setStringList(filtered);
m_word = word;
complete();
}
inline QString word()
{
return m_word;
}
private:
QStringList m_list;
QStringListModel m_model;
QString m_word;
};

I did it myself by creating a copy of my
m_listand searching it with thestartsWithfunction. I then added the found items to atempListand filtered thec_m_listas I did in my question. Thefilteredlist also got added to thetempList.Now it looks like this:
Code