Ich würde gerne eine QComboBox haben, deren QListView nur Items anzeigt, die zu dem passen, was man bisher im zugehörigen QLineedit eingegeben hat; also z.B.: Wenn man ein 'a' tippt, erscheinen in der Liste nur noch Items, die mit 'a' anfangen etc. Sollte eigentlich nicht so schwer sein mit QSortFilterProxyModel - dachte ich...
Code: Alles auswählen
#include <QApplication>
#include <QComboBox>
#include <QSortFilterProxyModel>
#include <QStringList>
int main(int argc, char** argv)
{
QApplication app(argc, argv);
QComboBox combo;
combo.setEditable(true);
combo.setCompleter(0);
combo.addItems(QStringList() << "aaa" << "aba" << "bbb" << 42);
// Set filter model
QSortFilterProxyModel* pFilterModel = new SortFilterProxyModel(&combo);
combo.model()->setParent(pFilterModel);
pFilterModel->setSourceModel(combo.model());
combo.setModel(pFilterModel);
// Use entered text as pattern for filter model
QObject::connect( &combo, SIGNAL(editTextChanged(const QString&)), pFilterModel, SLOT(setFilter(const QString&)) );
// Ok, do it
combo.show();
app.exec();
};
Weiß jemand Abhilfe?
Danke shaka