Search code examples
c++qtqcompleter

QCompleter not support up and down key


I use setEditable(true) to make QComboBox editable, when I input cy, then the completer's popup view will be visible and lists all possible results like: cyan, cyana, liecyan ... But when I press Down in keyboard (Qt::Key_Down), the first one cyan will be selected and QComboBox's lineedit's text will be set cyan , meanwhile, completer's popup view updates, only cyan shows. How can I customize it to make it behave like web's select component.


Solution

  • I have solved this question.

    1.class MyListView : public QListView

    2.MyListView's bool event(...) need to be implemented to concern about type is QEvent::ShortcutOverride

    3.based on QEvent::ShortcutOverride, when user press Qt:Key_Up or Qt::Key_Down,setfalg false, when user release key,set flag true

    3.QCompleter use setPopup(MyListView's instance) to override default listview 4. set QCompleter's regexp to work when falg is true 5.I got what I want