1. 输入内容自动配对
2. 在ui中添加comboBox组件
3. 代码实现,mainwindow.cpp
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include <QCompleter>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
QStringList wordList;
wordList << "出仓" << "入仓" << "获取TIP头" << "移除TIP头" << "血液预稀释" << "尿液预稀释" << "血液混匀加样" << "尿液混匀加样" << "模块检测";
ui->comboBox->addItems(wordList);
ui->comboBox->setEditable(true); //使能comboBox编辑功能
QCompleter *pCompleter = new QCompleter(wordList, this);//创建自动填充实例
pCompleter->setCaseSensitivity(Qt::CaseInsensitive); //大小写设置:不区分大小写
pCompleter->setFilterMode(Qt::MatchContains); //匹配类型:内容匹配
ui->comboBox->setCompleter(pCompleter);
}
MainWindow::~MainWindow()
{
delete ui;
}