输入内容, 列出可选的项: 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;
}

 

posted @ 2014-05-10 19:16  wiessharling  阅读(922)  评论(0编辑  收藏  举报