Reputation: 6964
We have a QGridLayout which has a particular row which is arranged like so:
+---------------------------+
| | | |
| A | B | C |
| | | |
+---------------------------+
At times, the QWidget (a QLabel) denoted as 'B' is hidden. When this occurs, I want widgets 'A' and 'C' (two QButtons) to redistribute 50/50. Later I would like to place 'B' back in the flow and give them their 20/60/20'ish layout.
I've tried B->hide()
B->setVisible(false)
layout->removeWidget(B)
but in each of these cases, 'B's space is still reserved on the screen.
Upvotes: 2
Views: 270
Reputation: 326
You have to change your layout (since it's a « grid », all the column have to be shrinked).
Instead of putting all 3 in the GridLayout, add them to a QHBoxLayout that you add with
gridLayout->addLayout(vLayout, 0, row, 1, -1)
Upvotes: 1
Reputation: 3493
Let's say you have colspan 10, then A would take 2 columns, B - 6 and C - 2
you add widgets to layout like this:
layout->addWidget(A,0,0,1,2); // 2 - is rowspan
layout->addWidget(B,0,2,1,6); // 6 - is rowspan
layout->addWidget(C,0,8,1,2); // 2 - is rowspan
There: 20-60-20, but when you need only A and C with 50 by 50, you need to remove A,B,C from layout and add them again as
layout->addWidget(A,0,0,1,5); // 5 - is rowspan
layout->addWidget(C,0,5,1,5); // 5 - is rowspan
Upvotes: 0