-
Notifications
You must be signed in to change notification settings - Fork 0
/
mycompleter.cpp
47 lines (37 loc) · 938 Bytes
/
mycompleter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "mycompleter.h"
MyCompleterLineEdit::MyCompleterLineEdit(QWidget *parent)
: QLineEdit(parent), c(0)
{
connect(this,SIGNAL(textEdited(QString)),this,SLOT(updateHint()));
}
MyCompleterLineEdit::~MyCompleterLineEdit()
{
}
void MyCompleterLineEdit::setCompleter(MyCompleter *completer)
{
if (c)
QObject::disconnect(c, 0, this, 0);
c = completer;
if (!c)
return;
c->setWidget(this);
connect(c, SIGNAL(activated(const QString&)), this, SLOT(insertCompletion(const QString&)));
}
MyCompleter *MyCompleterLineEdit::completer() const
{
return c;
}
void MyCompleterLineEdit::insertCompletion(const QString& completion)
{
setText(completion);
c->popup()->hide();
//selectAll();
//insert(completion);
setText(completion);
emit selectionChanged(completion);
}
void MyCompleterLineEdit::updateHint()
{
c->update(text());
c->popup()->setCurrentIndex(c->completionModel()->index(0, 0));
}