首页 > 代码库 > 输入内容, 列出可选的项: QComboBox

输入内容, 列出可选的项: QComboBox

#include "widget.h"
#include "ui_widget.h"
#include <QtGui/QCompleter>
#include <QStringList>

Widget::Widget(QWidget *parent)
    : QWidget(parent), ui(new Ui::Widget) {
    ui->setupUi(this);

    QStringList strings;
    strings << "Biao" << "Biao Huang" << "Mac" << "MacBook" << "MacBook Pro" << "Mac Pro";
    completer = new QCompleter(strings, this);

    ui->comboBox->clear();
    ui->comboBox->addItems(strings);
    ui->comboBox->setEditable(true);
    ui->comboBox->setCompleter(completer);
}

Widget::~Widget() {
    delete ui;
    delete completer;
}