I would like to fill a QGridLayout
with QWidgets
. The QWidgets
need to appear in a top-left to top-right fashion and proceed to fill the down downwards after each row is filled with QWidgets
. An example of a similar and familiar GUI is how Apple sorts its apps on the iPhone or iPad's home screen. The apps go top-left to top-right and proceed to go downward after each row is filled.
Right now, whenever I add elements, they take up the entirety of the screen and/or aren't added next to each other.
This is example code of what I am doing
m_gridLayout = new QGridLayout(this);
this->setLayout(m_gridLayout);
m_gridLayout->addWidget(widgetToBeAdded, m_currentRow, m_currentColumn, Qt::AlignLeft);
I proceed to update m_currentColumn and m_currentRow as expected. After a certain amount of columns, I tell it to change to the next row, and nothing happens. I have confirmed through debugging that it is infact spitting out the correct rows and columns.)
Eventually, I will need to throw on a QScrollArea
so that one can scroll down the grid.
The size of each QWidget
will be the same. If I could get any help in regards to sorting the grid properly, it would be much appreciated.
EDIT: Using the answer below, I have managed to get my items to sort in the correct order. However, there is a large amount of space in between all elements in the vertical direction. This is not obviated by changing the verticalSpacing property, as I would think. Does anyone know how to proceed?