示例#1
0
AddTagsLineEdit::AddTagsLineEdit(QWidget* const parent)
    : QLineEdit(parent),
      d(new Private)
{
    setClearButtonEnabled(true);

    d->completer = new TagCompleter(this);
    d->completer->setMaxVisibleItems(15);

    setCompleter(d->completer);

    connect(this, SIGNAL(returnPressed()),
            this, SLOT(slotReturnPressed()));

    connect(this, SIGNAL(editingFinished()),
            this, SLOT(slotEditingFinished()));

    connect(this, SIGNAL(textChanged(QString)),
            this, SLOT(slotTextChanged(QString)));

    connect(this, SIGNAL(textEdited(QString)),
            d->completer, SLOT(slotTextEdited(QString)));

    connect(d->completer, static_cast<void(TagCompleter::*)(const TaggingAction&)>(&TagCompleter::activated),
            [this](const TaggingAction& action){ completerActivated(action); });

    connect(d->completer, static_cast<void(TagCompleter::*)(const TaggingAction&)>(&TagCompleter::highlighted),
            [this](const TaggingAction& action){ completerHighlighted(action); });
}
示例#2
0
bool BAutoCompletionHelper::eventFilter(QObject *object, QEvent *event)
{
    if (event->type() != QEvent::KeyPress)
        return false;
    QKeyEvent *ke = static_cast<QKeyEvent *>(event);
    if (ke->key() != Qt::Key_Enter && ke->key() != Qt::Key_Return)
        return false;
    QAbstractItemView *popup = qobject_cast<QAbstractItemView *>(object);
    if (!popup || !popup->isVisible())
        return false;
    popup->hide();
    completerActivated(popup->currentIndex());
    ke->ignore();
    return true;
}