diff options
author | Thierry Bastian <thierry.bastian@nokia.com> | 2009-11-02 14:45:49 (GMT) |
---|---|---|
committer | Thierry Bastian <thierry.bastian@nokia.com> | 2009-11-02 14:47:17 (GMT) |
commit | 8abe466caa1b38f4cc1f95fba83d5e61e611e931 (patch) | |
tree | c08bb40f422a984af077da49ac9ba1e5981658df /src/gui/widgets/qcombobox.cpp | |
parent | 8d01f436451071a917c147a96a979ccdaee106f9 (diff) | |
download | Qt-8abe466caa1b38f4cc1f95fba83d5e61e611e931.zip Qt-8abe466caa1b38f4cc1f95fba83d5e61e611e931.tar.gz Qt-8abe466caa1b38f4cc1f95fba83d5e61e611e931.tar.bz2 |
Make the combobox emit activated when it loses focus
Task-number: QTBUG-1071
Reviewed-by: ogoffart
Diffstat (limited to 'src/gui/widgets/qcombobox.cpp')
-rw-r--r-- | src/gui/widgets/qcombobox.cpp | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/src/gui/widgets/qcombobox.cpp b/src/gui/widgets/qcombobox.cpp index 1879db4..bd1d8ba 100644 --- a/src/gui/widgets/qcombobox.cpp +++ b/src/gui/widgets/qcombobox.cpp @@ -1111,6 +1111,32 @@ void QComboBoxPrivate::updateLineEditGeometry() lineEdit->setGeometry(editRect); } +Qt::MatchFlags QComboBoxPrivate::matchFlags() const +{ + // Base how duplicates are determined on the autocompletion case sensitivity + Qt::MatchFlags flags = Qt::MatchFixedString; +#ifndef QT_NO_COMPLETER + if (!lineEdit->completer() || lineEdit->completer()->caseSensitivity() == Qt::CaseSensitive) +#endif + flags |= Qt::MatchCaseSensitive; + return flags; +} + + +void QComboBoxPrivate::_q_editingFinished() +{ + Q_Q(QComboBox); + if (lineEdit && !lineEdit->text().isEmpty()) { + //here we just check if the current item was entered + const int index = q_func()->findText(lineEdit->text(), matchFlags()); + if (index != -1 && itemText(currentIndex) != lineEdit->text()) { + q->setCurrentIndex(index); + emitActivated(currentIndex); + } + } + +} + void QComboBoxPrivate::_q_returnPressed() { Q_Q(QComboBox); @@ -1123,13 +1149,7 @@ void QComboBoxPrivate::_q_returnPressed() // check for duplicates (if not enabled) and quit int index = -1; if (!duplicatesEnabled) { - // Base how duplicates are determined on the autocompletion case sensitivity - Qt::MatchFlags flags = Qt::MatchFixedString; -#ifndef QT_NO_COMPLETER - if (!lineEdit->completer() || lineEdit->completer()->caseSensitivity() == Qt::CaseSensitive) -#endif - flags |= Qt::MatchCaseSensitive; - index = q->findText(text, flags); + index = q->findText(text, matchFlags()); if (index != -1) { q->setCurrentIndex(index); emitActivated(currentIndex); @@ -1664,6 +1684,7 @@ void QComboBox::setLineEdit(QLineEdit *edit) if (d->lineEdit->parent() != this) d->lineEdit->setParent(this); connect(d->lineEdit, SIGNAL(returnPressed()), this, SLOT(_q_returnPressed())); + connect(d->lineEdit, SIGNAL(editingFinished()), this, SLOT(_q_editingFinished())); connect(d->lineEdit, SIGNAL(textChanged(QString)), this, SIGNAL(editTextChanged(QString))); #ifdef QT3_SUPPORT connect(d->lineEdit, SIGNAL(textChanged(QString)), this, SIGNAL(textChanged(QString))); @@ -1960,7 +1981,7 @@ void QComboBoxPrivate::setCurrentIndex(const QModelIndex &mi) if (lineEdit) { QString newText = q->itemText(currentIndex.row()); if (lineEdit->text() != newText) - lineEdit->setText(q->itemText(currentIndex.row())); + lineEdit->setText(newText); updateLineEditGeometry(); } if (indexChanged) { |