Search code examples
qtqlistwidget

Make QListWidget return to first item clicking down


I have a GUI in Qt with a QListWidget showing different choices.

When I click down key, lower option becomes the selected one, but if I have selected the last one in the list, clicking down key does nothing.

I want that clicking down when I am in the last option makes it go to the first option again.

Do I have to implement a logic for this or is there any option in QListWidget that makes it behave like that?


Solution

  • You have to do that yourself. I see three options:

    1. Derive from QListWidget and override QAbstractItemView::moveCursor.
    2. Derive from QListWidget and override QAbstractItemView::keyPressEvent.
    3. Install an event filter on your list view and handle the KeyPress event.