Widgets in layout with stretch factor and no minimum size
-
I add several Qlabels to a layout, they are supposed to take a certain percentage of the layout.
//double weight = s[row][column]; QLabel *colorLabel = new QLabel(); QSizePolicy policy = colorLabel->sizePolicy(); policy.setHorizontalStretch(weight * 100); layout.addWidget(colorLabel);
The problem is, that weight can be very close to zero, in that case the label should not be displayed, it seems however that ther labels have a minimum size of 5 pixels. How can I change that?
The blue and brown part should not be visible according to the weight.
-
Hi,
In that case, set their visibility to false. That would make more sense to not show them rather than trying to give them a size "that should be zero but it's not exactly that".
-
That's possible, but I will have to decide on some cutoff value and when the layout resizes a label which should be hidden in a smaller parent might have to be shown. A lot of code, if I could just disable the minimum size it would be much easier and cleaner.
-
That's possible, but I will have to decide on some cutoff value and when the layout resizes a label which should be hidden in a smaller parent might have to be shown. A lot of code, if I could just disable the minimum size it would be much easier and cleaner.
@Fabian_Schmidt
Hi
I just tested with various widgets and it seems to come from layout and the
way in interprets setHorizontalStretch. a value of zero do not mean zero size
I have not seen a setting to disable/alter this. -
@Fabian_Schmidt
Hi
I just tested with various widgets and it seems to come from layout and the
way in interprets setHorizontalStretch. a value of zero do not mean zero size
I have not seen a setting to disable/alter this.@mrjj
I tried to use a minimum of 1, while the other values were close to 10000:// policy.setHorizontalStretch(std::max(1, (int)(weight * 10000)));
It still looks the same, so I think it's not just because of the zero.
-
@mrjj
I tried to use a minimum of 1, while the other values were close to 10000:// policy.setHorizontalStretch(std::max(1, (int)(weight * 10000)));
It still looks the same, so I think it's not just because of the zero.
@Fabian_Schmidt
Hi
I tried again with QFrames and it seems it can be zero size unlike QLabel that would keep the 5? pixels as minimum
there is 3 frames here but first is zero size
So it might be related to QLabel somehow but im not sure in which way. -
Thanks for the answers, I was fiddling around with it, but didn't find any satisfactory solution yet.
Basicaly what I want to achieve is something similar to a pie chart, just as a square and it should be resizable, the colors must not have a minimum size, especially not as much as 5 pixels.Is there any way besides writing a custom draw function?