Qt中的模糊匹配QCompleter和自动匹配
来源:互联网 发布:java方法的重载 编辑:程序博客网 时间:2024/05/16 12:13
转载自:http://hi.baidu.com/781609892/item/2b035e4cdf8dc480833ae19f
模糊匹配
1.利用QCompleter实现
QStringList wordList;
wordList << "alpha" << "omega" << "omicron" << "zeta";
QCompleter *completer = new QCompleter(wordList, this);
completer->setCaseSensitivity(Qt::CaseInsensitive);//·这个属性可设置进行匹配时的大小写敏感性
completer->setCompletionMode(QCompleter::InlineCompletion);//设置匹配时弹出的形式。
//QCompleter::InlineCompletion;
//QCompleter::PopupCompletion;
//QCompleter::UnfilteredPopupCompletion;
ui.lineEdit->setCompleter(completer);
2.自动完成的QLineEdit的匹配
http://blog.sina.com.cn/s/blog_6d1656130100pyvf.html参考博客
//构造函数中
model = new QStringListModel(this);
words = QStringList() << "Biao" << "Bin" << "Huang" << "Hua" << "Hello" << "BinBin" << "Hallo";
model->setStringList(words);
ui->listView->setModel(model);
connect(ui->listView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(completeText(const QModelIndex &)));
connect(ui->lineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(setCompleter(const QString &)));
//实现自动查询
void manualMW::setCompleter( QString serchtext )
{
serchtext = ui->lineEdit->text();
if (serchtext.isEmpty())
{
ui->listView->setModel(model);
}
// 如果完整的完成列表中的某个单词包含输入的文本,则加入要显示的完成列表串中
QStringList sl;
foreach(QString word, dbay_name_list)
{
if (word.contains(serchtext,Qt::CaseInsensitive))
{
sl << word;
}
}
model1->setStringList(sl);
if (model1->rowCount() == 0)
{
return;
}
ui->listView->setModel(model1);
}
void manualMW::keyPressEvent( QKeyEvent *e )
{
if (!ui->listView->isHidden())
{
int key = e->key();
int count = ui->listView->model()->rowCount();
QModelIndex currentIndex = ui->listView->currentIndex();
if (Qt::Key_Down == key) {
// 按向下方向键时,移动光标选中下一个完成列表中的项
int row = currentIndex.row() + 1;
if (row >= count)
{
row = 0;
}
QModelIndex index = ui->listView->model()->index(row, 0);
ui->listView->setCurrentIndex(index);
}
else if (Qt::Key_Up == key)
{
// 按向下方向键时,移动光标选中上一个完成列表中的项
int row = currentIndex.row() - 1;
if (row < 0)
{
row = count - 1;
}
QModelIndex index = ui->listView->model()->index(row, 0);
ui->listView->setCurrentIndex(index);
}
//else if (Qt::Key_Escape == key)
//{
// // 按下Esc键时,初始完成列表
// initListView(words);
//}
else if (Qt::Key_Enter == key || Qt::Key_Return == key)
{
// 按下回车键时,使用完成列表中选中的项
if (currentIndex.isValid())
{
QString selectedtext = ui->listView->currentIndex().data().toString();
QStringList sl;
sl<<selectedtext;
model->setStringList(sl);
ui->listView->setModel(model);
}
}
else
{
// 其他情况,隐藏完成列表,并使用QLineEdit的键盘按下事件
//listView->hide();
//QListView::keyPressEvent(e);
//initListView(words);
}
}
else
{
//QListView::keyPressEvent(e);
}
}
- Qt中的模糊匹配QCompleter和自动匹配
- QComboBox+QCompleter实现搜索自动匹配
- qt Qcompleter自动补全类
- jquery中的模糊匹配
- VC++ combobox模糊匹配,自动匹配
- 正则表达式中的模糊匹配
- SQL 中的模糊一一匹配
- grep 全词匹配和模糊匹配
- 模糊匹配
- 模糊匹配
- 模糊匹配
- easyui 模糊匹配解决办法 Firefox不会自动匹配
- 首字母自动匹配与模糊查询
- c# 实现ComboBox自动模糊匹配
- c# 实现ComboBox自动模糊匹配
- c# 实现ComboBox自动模糊匹配
- oracle中的截取,模糊匹配小结
- jquery中的模糊匹配查找标签
- js 常用方法收集
- (转) Java字符编码转换
- 源码世界讲解 php防止sql注入
- 显示 on the device! 运行后没图标 没反应的解决方法
- 实时查看某进程(xxx)的内存使用情况
- Qt中的模糊匹配QCompleter和自动匹配
- 手机里面的照片被误删了怎么找回?
- 排序算法之快速排序
- Eclipse设置、调优、使用
- PHP 获取栏目的【所有子级和孙级栏目】的ID号
- 移植OpenCv2.4.8到ARM
- php Memcache 中实现消息队列
- 黑马程序员之java编程基础5
- CentOS-min 操作记录(4)