Reprint: Http://www.cnblogs.com/csuftzzk/p/qss_lineedit_completer.html?utm_source=tuicool&utm_medium=referral
Reprint: http://blog.csdn.net/starcloud_zxt/article/details/5186489
Reprint: http://blog.sina.com.cn/s/blog_a6fb6cc90101gu7w.html
First, the window class. h
The header file to use
#include <QStandardItemModel>
// Auto-Complete qstandarditemmodel* M_model; Qcompleter* m_completer;
void onemailchoosed (const qstring& email); void ontextchanged (const qstring& str);
. cpp in
#include <QCompleter>
M_model in Constructors=NewQstandarditemmodel (0,1, This); M_completer=NewQcompleter (M_model, This); Ui.useredit-Setcompleter (M_completer); Connect (M_completer, SIGNAL (activated (Constqstring&)), This, SLOT (onemailchoosed (Constqstring&))); Connect (Ui.useredit, SIGNAL (textChanged (Constqstring&)), This, SLOT (OnTextChanged (Const(qstring&)));
voidQt_test::onemailchoosed (Constqstring&email) {Ui.useredit->clear ();//Clear text updates that already existUi.useredit->setText (email);}voidQt_test::ontextchanged (Constqstring&str) { if(Str.contains ("@"))//If you have entered the @ symbol, we stop the completion. Because at this point, it's not much of a matter of our complement. { return; } qstringlist strlist; Strlist<<"@163.com"<<"@qq. com"<<"@gmail. com"<<"@hotmail. com"<<"@126.com"; M_model->removerows (0, M_model->rowcount ());//clear the data that already exists, otherwise each time the text changes will insert the data, and finally the duplicate data appears for(inti =0; I < strlist.size (); ++i) {M_model->insertrow (0); M_model->setdata (M_model->index (0,0), str +strlist.at (i)); }}
Second, QT custom Password box, first show and then hide
Reprint: http://blog.csdn.net/caoshangpa/article/details/50978164
Reprint: http://www.waitingfy.com/archives/1165
#ifndef Qpasswordlineedit_h#defineQpasswordlineedit_h#include<QLineEdit>classQpasswordlineedit: Publicqlineedit{Q_object Public: //default input disappears after 300 millisecondsQpasswordlineedit (Qwidget *parent,intTimeout = -); ~Qpasswordlineedit (); //get a real passwordQString GetPassword (); //set display to hidden time interval voidSetTimeout (intmsec);PrivateSlots:voidSlotcursorpositionchanged (int,int); voidSlottextedited (Constqstring&); //Show hidden Passwords voidSlotdisplaymaskpassword ();Private: //get the hidden password, here is the asteriskQString Getmaskpassword ();Private: intmtimeout; QString Mlineedittext; //to the length of the last character intMlastcharcount;};#endif //Qpasswordlineedit_h
#include"qpasswordlineedit.h"#include<QTimer>#include<QDebug>Qpasswordlineedit::qpasswordlineedit (Qwidget*parent,inttimeout): Qlineedit (parent) {Mtimeout=timeout; Mlineedittext=""; Mlastcharcount=0; Connect ( This, SIGNAL (Cursorpositionchanged (int,int)), This, SLOT (Slotcursorpositionchanged (int,int))); Connect ( This, SIGNAL (textedited (Constqstring&)), This, SLOT (slottextedited (Constqstring&)));} Qpasswordlineedit::~Qpasswordlineedit () {}voidQpasswordlineedit::slotcursorpositionchanged (intOldpos,intNewpos) { if(oldpos>=-1&& newpos>=0 ) { if(newpos>Oldpos) {Qtimer::singleshot (mtimeout, This, SLOT (Slotdisplaymaskpassword ())); } Else { This-setcursorposition (Oldpos); } }}voidQpasswordlineedit::slotdisplaymaskpassword () { This-SetText (Getmaskpassword ());}voidQpasswordlineedit::slottextedited (Constqstring&text) { if(Text.count () >mlastcharcount)//input{mlineedittext.append (Text.right (1)); } Else if(Text.count () <mlastcharcount)//Delete{mlineedittext.remove (Mlineedittext.count ()-1,1); } Mlastcharcount=mlineedittext.count ();} QString Qpasswordlineedit::getpassword () {returnMlineedittext;}voidQpasswordlineedit::settimeout (intmsec) {Mtimeout=msec;} QString Qpasswordlineedit::getmaskpassword () {QString mask=""; intCount = This-text (). length (); if(count>0) { for(intI=0; i<count;i++) {Mask+="*"; } } returnMask;}
Select the password edit box, then right-click on the pop-up menu and select promote
Click Promote to complete, is not very simple
QT Note qlineedit Auto-completion and control elevation