diff options
author | Tomaz Canabrava <tcanabrava@kde.org> | 2013-07-17 11:47:23 -0300 |
---|---|---|
committer | Tomaz Canabrava <tcanabrava@kde.org> | 2013-07-17 11:47:23 -0300 |
commit | bad91ef11c49ad3e92e17e18ad66001bc0037f99 (patch) | |
tree | 3b3b13ea76c87ca25e0d3d340d6003dd77783e9e /qt-ui/modeldelegates.cpp | |
parent | 1a0a4b7e08df29dcc519dfe35022127e1d5dda20 (diff) | |
download | subsurface-bad91ef11c49ad3e92e17e18ad66001bc0037f99.tar.gz |
Added EnterKey to finish edition on Cyl/Weigths with the popup open
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 <tcanabrava@kde.org>
Diffstat (limited to 'qt-ui/modeldelegates.cpp')
-rw-r--r-- | qt-ui/modeldelegates.cpp | 20 |
1 files 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*>(qobject_cast<const QObject*>(this))); + comboDelegate->view()->installEventFilter( const_cast<QObject*>(qobject_cast<const QObject*>(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<QKeyEvent*>(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<QKeyEvent*>(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<QKeyEvent*>(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); + } } } |