×
Namespaces

Variants
Actions
(Redirected from 如何使用QCompleter)

Archived:如何使用QCompleter

From Nokia Developer Wiki
Jump to: navigation, search

Archived.png存档: 这篇文章是存档,因为考虑到今天它与第三方开发者建立商业解决方案不相关。

Widgets deprecated, Qt for S60 very old version, and whole page out of date with respect to site links etc.

Article Metadata

兼容于
平台:
Symbian

文章
dougcn 在 19 Mar 2009 创建
最后由 hamishwillee 在 14 Feb 2014 编辑
  • 适用平台:S60 3rd Edition FP2, S60 5th Edition
  • 开发工具:Qt Creator IDE
  • 关键字:QLineEdit,QStringList,QCompleter

Contents

概述

在Qt的任何小部件(Widget),比如QLineEdit和QComboBox,都可以使用QCompleter来完成自动完成功能。在用户开始输入字符时,QCompleter根据一个词汇列表给出完成这个词汇的多个备选项。参考:QCompleter


兼容性

  • 可以在Qt Creator IDE中运行,但不能在Carbide.c++中运行。

各种函数

  • 这个属性可设置进行匹配时的大小写敏感性
completer->setCaseSensitivity(Qt::CaseInsensitive);
  • 这个属性可设置给定词汇完成时如何呈现给用户
completer->setCompletionMode(QCompleter::InlineCompletion);
completer->setCompletionMode(QCompleter::QCompleter::UnfilteredPopupCompletion); 

Inlinecompleter.JPG

源代码

#include <QtGui/QApplication>
#include "qcomplimentwidget.h"
#include<QStringList>
#include<QLineEdit>
#include<QCompleter>
#include<QHBoxLayout>
#include<QWidget>
#include<QLabel>
 
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget *win=new QWidget();
QHBoxLayout *lay=new QHBoxLayout();
QStringList wordList;
wordList << "alpha" << "omega" << "omicron" << "zeta"<<"america"<<"orion"<<"amit"<<"Odssey";
QLabel *lbl=new QLabel("Select");
QLineEdit *lineEdit = new QLineEdit();
lbl->setBuddy(lineEdit);
QCompleter *completer = new QCompleter(wordList);
completer->setCaseSensitivity(Qt::CaseInsensitive); //Make caseInsensitive selection
//completer->setCompletionMode(QCompleter::InlineCompletion); //Used to enable in line searching
//completer->setCompletionRole(3);
lineEdit->setCompleter(completer);
lay->addWidget(lbl);
lay->addWidget(lineEdit);
win->setLayout(lay);
win->show();
return a.exec();
}

屏幕截图

关于QCompleter的更多信息QCompleter

Inlinecompleter1.JPG

内部链接

This page was last modified on 14 February 2014, at 06:38.
377 page views in the last 30 days.
×