Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

How to use QCompleter in Qt

From Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): S60 Emulator
Compatibility
Platform(s): S60 3rd Edition FP2, S60 5th Edition
Symbian
S60 5th Edition
S60 3rd Edition FP2
Article
Keywords: QCompleter
Created: mind_freak (17 Mar 2009)
Last edited: hamishwillee (23 Jan 2013)

Contents

Overview

This example shows how to use QCompleter to provide auto completion of words entered into a QLineEdit. When the user starts typing a word, QCompleter suggests possible options for word completion, based on a supplied word list.

Preconditions

  • Download and install the Qt SDK

Various Function

  • This property holds the case sensitivity of the matching.
completer->setCaseSensitivity(Qt::CaseInsensitive);
  • This property holds how the completions of a specific words are provided to the user.
completer->setCompletionMode(QCompleter::InlineCompletion);
completer->setCompletionMode(QCompleter::QCompleter::UnfilteredPopupCompletion); 

Com.JPG

  • This property holds the item role to be used to query the contents of items for matching.
completer->setCompletionRole(3);


Source Code

#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->showMaximized();
win->setStyleSheet("* { background-color:rgb(199,147,88); padding: 7px ; color:rgb(255,255,255)}");
return a.exec();
}


Screenshot

Completer001.jpg

This page was last modified on 23 January 2013, at 06:34.
168 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×