From bad91ef11c49ad3e92e17e18ad66001bc0037f99 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Wed, 17 Jul 2013 11:47:23 -0300 Subject: [PATCH] Added EnterKey to finish edition on Cyl/Weigths with the popup open MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit So, I used the Qt Event Filter strategy to bypass the normal role of user interaction, the Qt ComboBox needed 2 keypresses to close and edit. so I grabbed the first one and send together a second one. Há. Signed-off-by: Tomaz Canabrava --- qt-ui/modeldelegates.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp index e99f13ea7..97a00a461 100644 --- a/qt-ui/modeldelegates.cpp +++ b/qt-ui/modeldelegates.cpp @@ -83,6 +83,7 @@ QWidget* ComboBoxDelegate::createEditor(QWidget* parent, const QStyleOptionViewI comboDelegate->setAutoCompletionCaseSensitivity(Qt::CaseInsensitive); comboDelegate->completer()->setCompletionMode(QCompleter::PopupCompletion); comboDelegate->lineEdit()->installEventFilter( const_cast(qobject_cast(this))); + comboDelegate->view()->installEventFilter( const_cast(qobject_cast(this))); connect(comboDelegate, SIGNAL(highlighted(QString)), this, SLOT(testActivation(QString))); currCombo.comboEditor = comboDelegate; currCombo.currRow = index.row(); @@ -100,9 +101,22 @@ bool ComboBoxDelegate::eventFilter(QObject* object, QEvent* event) { // Reacts on Key_UP and Key_DOWN to show the QComboBox - list of choices. if (event->type() == QEvent::KeyPress){ - QKeyEvent *ev = static_cast(event); - if(ev->key() == Qt::Key_Up || ev->key() == Qt::Key_Down){ - currCombo.comboEditor->showPopup(); + if (object == currCombo.comboEditor){ // the 'LineEdit' part + QKeyEvent *ev = static_cast(event); + if(ev->key() == Qt::Key_Up || ev->key() == Qt::Key_Down){ + currCombo.comboEditor->showPopup(); + } + } + else{ // the 'Drop Down Menu' part. + QKeyEvent *ev = static_cast(event); + if( ev->key() == Qt::Key_Enter || ev->key() == Qt::Key_Return + || ev->key() == Qt::Key_Tab || ev->key() == Qt::Key_Backtab + || ev->key() == Qt::Key_Escape){ + // treat Qt as a silly little boy - pretending that the key_return nwas pressed on the combo, + // instead of the list of choices. this can be extended later for + // other imputs, like tab navigation and esc. + QStyledItemDelegate::eventFilter(currCombo.comboEditor, event); + } } }