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

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

}


你可能感兴趣的:(Qt: 输入内容, 列出可选的项: QComboBox)