Important: Please read the Qt Code of Conduct -

GridLayout and screen rotation

  • Hi all,

    I've started using a GridView to show a series of items on the screen. The GridView automatically adapts itself to the screen size so that, all the elements (a series of QML canvas, items in my case) are visibile. This is particularly useful on tablets in which screen coordinates can interchange. However, it feels to me like the GridView is largely underused for my purposes: I just need to spread out my canvas items in the available space.

    I've tried to use the GridLayout and the overall result satisfies me BUT I have lost the adaptability of the GridView. Once I rotate the tablet, the grid still sits horizontally, showing just its central part. Shouldn't the layout resize items according to the available space? Must I intercept the rotation signal? Any advice is really appreciate.

    Thanks in advance,

  • Maybe the ObjectModel (aka VisualItemModel) with GridView might be helpful for you.

  • It seems to pack together the flexibility of GridView with the semplicity of using a Layout. I'll give it a try. Thanks Juergen!

    Just another, probably stupid, question. One of the reasons to switch to GridLayout was the (not proven) fear that GridView could have more overheads than a layout. Hence, the question is: using a GridView instead of layout-ing items in a GridLayout can have any (sort of significant) impact on the performance of the application?

  • No. For larger amount of data the GridView will be more efficient, as it creates the delegates on demand. As a rule of thumb: If you need to layout your screen into a grid with a rather fixed amount of items, use Grid and GridLayout. If you have a uncertain or even growing amount of Items better to use GridView. The "View" part of GridView expresses the patterns it's the visual part of a data model. It really depends on your problem (grid of a photos => GridView, Layout of UI Items => GridLayout)

  • Thanks for the great explanation!
    I ended up using the GridView with the ObjectModel. Seems to work as I expected. Thanks again.

Log in to reply