[Qt-interest] how to make such a completer
yunqiu liu
yunqiuliu at yahoo.com
Wed Jan 5 03:04:10 CET 2011
Hi Wenjie:
You could try like the following:
1, Sub-class QLineEdit like scLineEdit,
2, in the scLineEdit definition,
1> create an object QComplete like ObjComplete;
2> create an object QStandardItemModel like objItemMode;
3> objComplete->setModel(objItemMode);
4> objComplete->setCompletionMod(QCompleter::PopupCompletion);
5> adjust the objComplete's font,something else;
6> setCompleter(objComplete);
7> adjust the background color of "this" if you like.
Somewhere, new an object of scLineEdit like objscLineEdit;
connect(objscLineEdit,SIGNAL(textEdit(const QString &)),
this,SLOT(haha_slot(const QString &)));
QList<QString> ls; //get from some place.
void the_this::haha_slot(const QString &text){
if (text.isEmpty() || text.length()<2 ) return;
csLineEdit sc=qobject_cast<scLineEdit *>(sender());
QStandardItemModel *model=sc->get_cleared_itemMode();
QStandardItem *invis=model->invisibleRootItem();
for(int i=0,sz=ls.size();i<sz;++i){
QString t = ls.at(i)+"\n";
int len=t.length();
if (len<=20 && len>0) {
QStandardItem *item=new QStandartItem;
item->setText(t);
invis->appendRow(item);
}
}
}
Just my 2 cents,
YQ
________________________________
From: wenjie sha <wenjiesha.victor at gmail.com>
To: qt-interest at qt.nokia.com
Sent: Tue, January 4, 2011 3:58:00 PM
Subject: [Qt-interest] how to make such a completer
Dear forum:
I want to create such a completer:
1.when user input the first alphabet, it doesn't pop any options
2.when user start entering the second alphabet, the popup only contains maximum
20 words.
3. I will have to be able to modify how the options are selected.
4. ....
Can someone tip me what changes I should make to what files?
And I still don't get how qcompleter and qlineedit communicate, also using
signal-slot mechanism?
Many thanks,
--
Wenjie Sha
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110104/b2fee4c0/attachment.html
More information about the Qt-interest-old
mailing list