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



  • 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?


  • Moderators

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



  • @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.


  • Qt Champions 2016

    @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)



  • @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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.