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. Render QListView like QTableView
Qt 6.11 is out! See what's new in the release blog

Render QListView like QTableView

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 2.5k Views 1 Watching
  • 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.
  • dadaD Offline
    dadaD Offline
    dada
    wrote on last edited by dada
    #1

    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

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      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.

      1 Reply Last reply
      0
      • dadaD Offline
        dadaD Offline
        dada
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          1
          • dadaD Offline
            dadaD Offline
            dada
            wrote on last edited by dada
            #5

            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]

            [x]

            1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi
              Oh you need something like

              [0] [1] [2]

              [x]

              [4] [5] [x]
              [x]

              is empty ?

              1 Reply Last reply
              0
              • dadaD Offline
                dadaD Offline
                dada
                wrote on last edited by dada
                #7

                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.

                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