Qt World Summit: Register Today!

How to move selection from top to bottom in list widget

  • Hello,
    I am using a QListWidget that contains a fixed number of items in it. When the top item is selected and the user presses the UP key, I need the selection to wrap around to the bottom item. I need the reverse when the bottom is selected and the user press the DN key, the selection goes to the top.

    I've tried using an eventFilter for the list and caught the UP and DOWN keypresses and detected if a wrap around is necessary. If so the ui->listMenu_->setCurrentRow(0 or count() -1). The problem here is that the resulting wrap when going up ends up on the second to last item, or when down, it ends on row 2. I understand why this is happening, I just don't know how to get my needed results.

    This is for an embedded Linux project where the QListWidget is used as a menu.

  • I guess what you do in your filter, is that you change the current selection, but do not eat the actual event. Make your event filter implementation return true if you are wrapping around.

  • Worked great. Thanks!

Log in to reply