Render QListView like QTableView



  • Hi guys

    I dont really know how to call what i want. And because of that, i wasn't able to search for it properly.

    I've got a simple list-model and i'm rendering it in a QListview. And that works fine. But is there a way to render a QListView like a Table?

    Lets take 3 columns for example. That should look like that. (the number is the id from that data in the model)
    How it looks like normaly:
    [0]
    [1]
    [2]
    [3]
    ....

    How i want it to look like:
    [0] [1] [2]
    [3] [4] [5]
    ....

    Ich hope you know what I mean?

    dada


  • Qt Champions 2016

    Hi and welcome
    Have a look at the flow setting
    http://doc.qt.io/qt-5.5/qlistview.html#flow-prop

    Setting it to LeftToRight might do what you want :)
    Also set isWrapping to true
    Also look at gridsize.



  • Nope, doesn't work. It changes it from:
    [0]
    [1]
    [2]
    [3]
    ...

    to:
    [0] [1] [2] [3] [4] .....

    Howerver, if there's no easy way i'll use a QTableView and change the data-method in the model to act like an table but with an 1D array. Like that: (I use Qt only in Python, so i'm showing you python)

    return data[(row - 1) * 3 + column]
    

    I think that should work

    But thank you anyway


  • Qt Champions 2016

    well it will wrap at widgets border
    so if u need it to wrap before, u might try icon mode/grid mode.
    http://stackoverflow.com/questions/11379816/qlistview-in-gridmode-auto-stretch-with-fixed-items-on-a-row-column

    Well using QTableView does seems like a better fit then.



  • Thank you! That works great. :D

    The Tableview would have worked too. But there's the problem, the view expects, that every row has the same amount of columns... There would it be a litle tricky (x) :
    [0] [1] [2]
    [3] [x] [x]


  • Qt Champions 2016

    Hi
    Oh you need something like

    [0] [1] [2]
    [3] [x] [x]
    [4] [5] [x]
    [6] [x] [x]

    where [x] is empty ?



  • Nope. I need what you postet^^

    But before your post, i tried to archive my goal with an QTableView. But there occured some issues when your datamodel hasn't enaugh items to fill the last row completly. You know what i mean?

    But it doesnt care anymore. Your solution works fine.


Log in to reply
 

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