I want to make a simple grid with QListView, e.g 3×3, but the gridSize() option in QListView doesn’t work that way, it’s the width/height of all child widgets in QListView, how should I do that ?
I want to make a simple grid with QListView , e.g 3×3, but the
Share
While I had thought the gridSize was the entire list, its actually per cell. The key things here are to set the resize mode to adjust, so that its always re-evaluating the item sizes, and also to keep adjusting the gridSize every time the list widget resizes. In my example, I am using an event filter, but you could also subclass the list and re-implement the resizeEvent.
The size of the list is divided by 3 and then some padding is removed for the scrollbars. The result is that the items are laid out in 3x width and keep resizing with the view.