Created
January 25, 2013 11:45
-
-
Save lamprosg/4633819 to your computer and use it in GitHub Desktop.
Qt - QCompleter (auto completions)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "dialog.h" | |
| #include "ui_dialog.h" | |
| Dialog::Dialog (QWidget *parent): | |
| QDialog(parent), | |
| ui(new UI::Dialog) | |
| { | |
| ui->setupUI(this); | |
| /***Set the autocompletion*****/ | |
| //Using a string list | |
| QStringList CompletionList; //Create a string list | |
| CompletionList << "Bryan" << "Bart" << "Brad" << "Beth"; //Add members to the string list | |
| StringCompleter = new QCompleter(CompletionList, this); //Initializing QCompleter with a reference to the CompletionList | |
| StringCompleter->setCaseSensitivity(Qt::CaseInsensitive); //Don't care for case sensitivity | |
| ui->lineEdit->setCompleter(StringCompleter); | |
| /*-------------------------------------------------------*/ | |
| //Using a Model | |
| ModelCompleter = new QCompleter(this); | |
| ModelCompleter->setModel(new QDirModel(ModelCompleter)); | |
| ui->lineEdit_2->setCompleter(ModelCompleter); | |
| /***Autocompletion is set******/ | |
| } | |
| Dialog::~Dialog() | |
| { | |
| delete ui; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Dialog based app with Base class QDialog | |
| #include <QDialog> | |
| #include <QCompleter> //include the header file | |
| #include <QDirModel> //For directory autocompetions | |
| namespace UI { | |
| class Dialog; | |
| } | |
| class Dialog : public QDialog | |
| { | |
| Q_OBJECT | |
| explicit Dialog (QWidget *parent=0); | |
| ~Dialog(); | |
| private: | |
| UI::Dialog *ui; | |
| QCompleter *StringCompleter; //Our 2 pointers to QCompleter objects | |
| QCompleter *ModelCompleter; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment