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>
This commit is contained in:
Tomaz Canabrava 2013-07-17 11:47:23 -03:00
parent 1a0a4b7e08
commit bad91ef11c

View file

@ -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,11 +101,24 @@ 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){
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);
}
}
}
return QStyledItemDelegate::eventFilter(object, event);
}