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 represent a list in a 2-by-n grid?

How to represent a list in a 2-by-n grid?

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

    I have a list of objects which I would like to represent as a 2-by-n grid that scrolls horizontally. Conceptually, this would be similar to a list view that scrolled horizontally and organized entries ordered by rows. However, I couldn't find any reference on any view class that fits these requirements. Does anyone know if Qt offers any view that is able to represent entries in a n-by-m grid, where n is hard-coded?

    jsulmJ 1 Reply Last reply
    0
    • R rmam

      I have a list of objects which I would like to represent as a 2-by-n grid that scrolls horizontally. Conceptually, this would be similar to a list view that scrolled horizontally and organized entries ordered by rows. However, I couldn't find any reference on any view class that fits these requirements. Does anyone know if Qt offers any view that is able to represent entries in a n-by-m grid, where n is hard-coded?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @rmam Sounds like you are talking about a table, right? QTableWidget/QTableView are worth checking.
      Or you can use a QScrollArea and QGridLayout.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • R Offline
        R Offline
        rmam
        wrote on last edited by
        #3

        @jsulm it does sound like a table (being a grid and all) but while table models are 2D, list models are 1D. I was expecting that Qt offered a way to get a view to map a 1D model to a 2-by-n grid (or i-by-n, being i constant but greater than 1).

        The QListView component does support a gridSize property, as well as flow and layoutMode, but I haven't found a working example or managed to get it to work.

        mrjjM 1 Reply Last reply
        0
        • R rmam

          @jsulm it does sound like a table (being a grid and all) but while table models are 2D, list models are 1D. I was expecting that Qt offered a way to get a view to map a 1D model to a 2-by-n grid (or i-by-n, being i constant but greater than 1).

          The QListView component does support a gridSize property, as well as flow and layoutMode, but I haven't found a working example or managed to get it to work.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @rmam said in How to represent a list in a 2-by-n grid?:

          The QListView component does support a gridSize property, as well as flow and layoutMod

          Hi, you might want to set ViewMode to IconMode. (from listmode)

          1 Reply Last reply
          0
          • R Offline
            R Offline
            rmam
            wrote on last edited by rmam
            #5

            @mrjj thanks for the tip. It seems it worked. I've toyed around with a QListView and I've managed to get it to list items in a 2-by-m grid.

            Here's what I did to get a QListView to present entries in a 2-by-m grid with entries sorted by row:

            • set QListView::viewMode to QListView::IconMode

            • set QListView::flow to QListView::TopToBottom

            Update: here's a link to another discussion on a similar problem: Model views with pagination.

            1 Reply Last reply
            1

            • Login

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