Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to move selection from top to bottom in list widget
QtWS25 Last Chance

How to move selection from top to bottom in list widget

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    ShawnG
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        ShawnG
        wrote on last edited by
        #3

        Worked great. Thanks!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved