summaryrefslogtreecommitdiffstats
path: root/qt-ui/modeldelegates.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-07-16 15:31:44 -0300
committerGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-07-16 15:31:44 -0300
commitc5a0c4e0d7f69be9341cc5c8815afe9761e5c47c (patch)
tree6eb3532a89e3ab292ec9ab2314ba702c797226a4 /qt-ui/modeldelegates.cpp
parentee25edc28ec8b254d31e24d7ba16642a60793289 (diff)
downloadsubsurface-c5a0c4e0d7f69be9341cc5c8815afe9761e5c47c.tar.gz
Support for key_up and down in the combobox delegate.
Adds spport for key_up and key_down in the combobox delegates, now when you press key_up or down, it will show the list of choices instead of going one-by-one in the lineedit. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Diffstat (limited to 'qt-ui/modeldelegates.cpp')
-rw-r--r--qt-ui/modeldelegates.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp
index 3aeaa02b5..28a6689b8 100644
--- a/qt-ui/modeldelegates.cpp
+++ b/qt-ui/modeldelegates.cpp
@@ -12,6 +12,8 @@
#include <QComboBox>
#include <QCompleter>
#include <QLineEdit>
+#include <QKeyEvent>
+#include <QAbstractItemView>
StarWidgetsDelegate::StarWidgetsDelegate(QWidget* parent):
QStyledItemDelegate(parent),
@@ -65,6 +67,7 @@ void ComboBoxDelegate::setEditorData(QWidget* editor, const QModelIndex& index)
c->setEditText(data);
}
+QComboBox *comboEditor;
QWidget* ComboBoxDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
QComboBox *comboDelegate = new QComboBox(parent);
@@ -73,9 +76,26 @@ QWidget* ComboBoxDelegate::createEditor(QWidget* parent, const QStyleOptionViewI
comboDelegate->setAutoCompletion(true);
comboDelegate->setAutoCompletionCaseSensitivity(Qt::CaseInsensitive);
comboDelegate->completer()->setCompletionMode(QCompleter::PopupCompletion);
+ comboDelegate->lineEdit()->installEventFilter( const_cast<QObject*>(qobject_cast<const QObject*>(this)));
+ comboEditor = comboDelegate;
return comboDelegate;
}
+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){
+ QString curr = comboEditor->currentText();
+ comboEditor->showPopup();
+ return true;
+ }
+ }
+
+ return QStyledItemDelegate::eventFilter(object, event);
+}
+
void ComboBoxDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
QRect defaultRect = option.rect;