Parcourir la source

Added selection from the QCompleter in ctkMenuComboBox.

Benjamin Long il y a 13 ans
Parent
commit
9b5e0233ad
2 fichiers modifiés avec 10 ajouts et 4 suppressions
  1. 9 3
      Libs/Widgets/ctkMenuComboBox.cpp
  2. 1 1
      Libs/Widgets/ctkMenuComboBox.h

+ 9 - 3
Libs/Widgets/ctkMenuComboBox.cpp

@@ -93,6 +93,8 @@ void ctkMenuComboBoxPrivate::init()
 
   this->SearchCompleter = new QCompleter(QStringList(), q);
   this->SearchCompleter->setCaseSensitivity(Qt::CaseInsensitive);
+  q->connect(this->SearchCompleter, SIGNAL(activated(const QString&)),
+             q, SLOT(onEditingFinished()));
 
   // Automatically set the minimumSizeHint of the layout to the widget
   layout->setSizeConstraint(QLayout::SetMinimumSize);
@@ -170,8 +172,8 @@ void ctkMenuComboBoxPrivate::setComboBoxEditable(bool edit)
       {
       ctkSearchBox* line = new ctkSearchBox();
       this->MenuComboBox->setLineEdit(line);
-      q->connect(line, SIGNAL(returnPressed()),
-                 q,SLOT(onReturnPressed()));
+      q->connect(line, SIGNAL(editingFinished()),
+                 q,SLOT(onEditingFinished()));
       }
     this->MenuComboBox->setCompleter(this->SearchCompleter);
     }
@@ -433,9 +435,13 @@ void ctkMenuComboBox::clearActiveAction()
 }
 
 // -------------------------------------------------------------------------
-void ctkMenuComboBox::onReturnPressed()
+void ctkMenuComboBox::onEditingFinished()
 {
   Q_D(ctkMenuComboBox);
+  if (!d->MenuComboBox->lineEdit())
+    {
+    return;
+    }
   QAction* action = d->actionByTitle(d->MenuComboBox->lineEdit()->text(), d->Menu.data());
   if (!action)
     {

+ 1 - 1
Libs/Widgets/ctkMenuComboBox.h

@@ -104,7 +104,7 @@ protected slots:
   /// action selected from the menu.
   void onActionSelected(QAction* action);
   /// action selected from the line edit or the completer.
-  void onReturnPressed();
+  void onEditingFinished();
 
 protected:
   QScopedPointer<ctkMenuComboBoxPrivate> d_ptr;