Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update QGridLayout row/column count depending on the layout size?

This thing seems really basic to me, though I could not find any information on how to implement it.

I have some sort of QGridLayout that contains equally-sized widgets. I would like to update its row/column count based on the layout size.

For instance, on a relatively wide screen, it would look like this:

wide screen

But if the screen is not wide enough to fit all the items it would grow vertically like this:

narrow screen

like image 637
bashis Avatar asked Oct 23 '25 06:10

bashis


1 Answers

The QGridLayout doesn't support this automatically. You can either:

  1. Use QGridLayout with a number of columns set according to screen width divided by the widget width, and the number of rows sufficient to fit the widgets, or

  2. Use the flow layout example and modify to your needs.

like image 160
Kuba hasn't forgotten Monica Avatar answered Oct 26 '25 03:10

Kuba hasn't forgotten Monica



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!