45 completer()->setCompletionMode( QCompleter::PopupCompletion );
46 completer()->setCaseSensitivity( Qt::CaseInsensitive );
51 if( strings.size() == 0 )
55 if( strings.size() == 1 )
59 QString common_prefix;
65 if( char_index >= strings[ 0 ].size() )
69 const QChar c = strings[ 0 ][ char_index ];
72 for(
int string_index = 1; string_index < strings.size(); string_index++ )
74 const QString& str = strings[ string_index ];
75 if( char_index >= str.size() ||
76 str[ char_index ] != c )
89 if( event->type() == QEvent::KeyPress )
91 QKeyEvent* k = (QKeyEvent*) event;
92 if( k->key() == Qt::Key_Tab && k->modifiers() == Qt::NoModifier )
94 QCompleter* comp = completer();
96 QStringList completions;
97 for(
int i = 0; comp->setCurrentRow( i ); i++ )
99 completions.push_back( comp->currentCompletion() );
102 if( max_common_prefix.size() >
currentText().size() )
104 setEditText( max_common_prefix );
105 lineEdit()->setCursorPosition( max_common_prefix.size() );
112 return ComboBox::event( event );
QString findMaxCommonPrefix(const QStringList &strings)
virtual bool event(QEvent *event)
If event is a tab key press, set the edit text to the longest common prefix from the completer...
EditableComboBox(QWidget *parent=0)