当前位置:网站首页>The use of QCompleter for Qt auto-completion
The use of QCompleter for Qt auto-completion
2022-08-04 17:03:00 【Autodesk_Glodon】
QCompleterAutomatic filling function can be realized,方便用户输入,提升用户的体验,一般和QLineEdit与QComboBox搭配起来使用.QCompleterThe class provides the modelitem的提示功能.
目的:The search box is often used to autocomplete searches.
效果:
代码如下:
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include<QCompleter>
#include<QFileSystemModel>
#include<QDirModel>
#pragma execution_character_set("utf-8")
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
QStringList itemList;
itemList << "北京市" << "河北省" << "河南省" << "test" << "HCTest";
// 下拉框添加数据
ui->comboBox->addItems(itemList);
// 设置可编辑
ui->comboBox->setEditable(true);
// 自动补全实例的构建
QCompleter *comp = new QCompleter(itemList,ui->comboBox->model());
// 设置匹配模式,只要包含就显示
comp->setFilterMode(Qt::MatchContains);
// 设置大小写区分,不区大小写
comp->setCaseSensitivity(Qt::CaseInsensitive);
// 设置向用户提供补全的方式
comp->setCompletionMode(QCompleter::PopupCompletion);
// 装载补全实例
ui->comboBox->setCompleter(comp);
QStringList word_list;
word_list<<"XiaoTu"<<"xiaomi"<<"Huawei"<<"huafei"<<"Shanghai"<<"shangshan"<<"abc";
QCompleter *completer = new QCompleter(word_list, this);
// 设置匹配模式,只要包含就显示
completer->setFilterMode(Qt::MatchContains);
// 设置大小写区分,不区大小写
completer->setCaseSensitivity(Qt::CaseInsensitive);
// 设置向用户提供补全的方式
completer->setCompletionMode(QCompleter::PopupCompletion);
ui->lineEdit->setCompleter(completer);
QCompleter *completer2 = new QCompleter(this);
completer2->setModel(new QDirModel(completer2));
ui->syslineEdit->setCompleter(completer2);
}
MainWindow::~MainWindow()
{
delete ui;
}
边栏推荐
- Hubei Mobile ZTE B860AV2.1_S905L_ flash firmware package
- R语言使用cov函数计算矩阵或者dataframe数据变量之间的协方差、cor函数计算相关性、cor函数通过method参数指定相关性、相关性计算方法Pearson,Spearman, Kendall
- 【商家联盟】云平台—异业联盟,打造线上线下商业相结合的系统
- 刷爆朋友圈!Alibaba出品亿级并发设计速成笔记太香了!
- 学习探索-给字体设置前景色
- Analysis of the gourd baby
- win11如何退出安全模式
- 移动魔百盒CM211-1_YS代工_S905L3B_RTL8822C_线刷固件包
- LeetCode 1403.非递增顺序的最小子序列
- 数字化金融企业的产品体系长啥样?
猜你喜欢
随机推荐
机器人示教编程与离线编程的优缺点对比
电气成套设备行业如何借助ERP系统,解决企业管理难题?
为什么买域名必须实名认证?这样做什么原因?
GraphQL 入门与实践
taro 滚动组件ScrollView
安装win11提示开启安全模式如何解决
理财产品买入后份额是固定不变的吗?
Cesium快速上手0-Cesium安装与基本介绍
软件基础的理论
最小区间覆盖
Hubei Mobile ZTE B860AV2.1_S905L_ flash firmware package
Compose 类型稳定性注解:@Stable & @Immutable
广东移动魔百盒M411A _905L3_线刷固件包
拼多多详情API接口深度解读
接口测试项目(非常值得练手)
ES中同时使用should和must导致只有must生效解决方案
ctfshow 萌新web1-21
Boost库学习笔记(一)安装与配置
WEB 渗透之SSTI 模板注入
JSP 标准标签库(JSTL)[通俗易懂]