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 programmatically select multiple rows in QListView?

How to programmatically select multiple rows in QListView?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 2.1k 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.
  • A Offline
    A Offline
    ablan
    wrote on last edited by
    #1

    I have written a program where the user can select multiple rows from a QListView. Sometimes the program need to load a set of selection at startup, so the program needs to be able to select multiple rows from code. How can this be done?

    1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by
      #2

      Use the correct QListView method to get the container of items in the list, iterate through it, and set the "checked/selected" attribute for each item that matches your selection cirteria.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        ablan
        wrote on last edited by ablan
        #3

        Sorry, can you show me how it is written in code?

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You should take a look at QItemSelectionModel::select()

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          A 1 Reply Last reply
          2
          • Christian EhrlicherC Christian Ehrlicher

            You should take a look at QItemSelectionModel::select()

            A Offline
            A Offline
            ablan
            wrote on last edited by
            #5

            @Christian-Ehrlicher
            Ok thanks! I got it to work.

            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