I want to create a resizable window that contains some icons that resize according to window. I created a window and placed the icons in a grid layout, it worked as i wanted so far.
But the problem is that when I shrink the window to tiny size, icons are too small and can't recognize at all. So I set the minimum size of the icons and it seemed to solve the first problem.
Now, the problem is that icons are overlap when I shrink the window and it looks ugly.
I tried using spacer, widget margin, spacing of layout and minimumRowHeight property.
But Qt seems the window size is higher priority than widget's minimum size or margin or other.
They all shrink and still no space at all between widgets.
I can solve this problem with minimum size of window. However, it will take several attempts to determine the best looking minimum size.
So my question is:
I wonder if there is a margin(or spacing) between widgets in layout that never shrink. If there is, I just place my icons in a generous window size and set a margin that doesn't shrink, so the minimum size of window can be determined it self.
If not, what is best way to make what I want? is that minimum size of window? If then, how do I determine the best minimum size?
Any advice or documentation would be highly appreciated.
Add:
- This is what I want. I set the minimum height of window to 380px.
- If I'm not set the minimum height, the icons are overlap as above
- I changed height several times to determine the height of the image at 1, if the height is not enough, the icons too close as shown
Here's some code:
verticalLayout = new QVBoxLayout(widget); // window layout
labelTime = new QLabel(widget);
verticalLayout->addWidget(labelTime);
gridLayout1 = new QGridLayout(); // grid layout at top
gridLayout1->setSpacing(15);
labelIcon1 = new QLabel(widget);
labelIcon1 ->setMinimumSize(QSize(40, 40));
labelIcon1 ->setPixmap(QPixmap(path));
gridLayout1->addWidget(labelIcon1, 0, 0, 1, 1);
... // create icons and add to gridlayout1
verticalLayout->addLayout(gridLayout1);
line = new QFrame(widget); // just line.
verticalLayout->addWidget(line); // add to vertical layout, not grid layout.
... // create grid layout, icons at bottom and add it to vertical layout, same as top
Structure looks like this: QLabel, QGridLayout, Line, QGridLayout2 are placed in a vertical layout.
-------------vertical layout
[ text ]
-------------grid layout
[icon][text]
[icon][text]
-------------grid layout
[ line ]
-------------grid layout 2
[icon][text]
[icon][text]
[icon][text]
-------------grid layout 2
-------------vertical layout