c++qtuser-interfaceqt3

Filter Widget using QComboBox


I want to implement Filter widget using QComboBox. The way it should work is, when I type letter 'a' it should show the items that are starting with 'a', and then if I type 'b' it should show the items that have the prefix 'ab' etc. I tried by overriding keyPressEvent of QComboBox class, but it didn't work. The main problem I got is, how can I make the QComboBox editable while the drop down list is appearing ? I'm opening dropdown list inside the key press event like this,

void SearchCombo::keyPressEvent(QKeyEvent *e)
{
    ...
    listBox()->popup();
    ...
}

Solution

  • I found a solution. What i did is, passing the QListBox's (QComboBox has a listbox) keyPressEvent's QKeyEvent to the QComboBox's LineEdit. Inside the LineEdit overrode keyPressEvent called using that QKeyEvent