QLabel in a layout: check whether or not setText() will cause the layout to expand
I have a
QComboBoxin a horizontal layout. The problem is that when I put long text in the label, it causes the layout to expand, which leads to the whole main window expanding. I want to avoid that by compacting the text if necessary, but how can I check before hand whether or not
setTextcall will stretch the window?
Note: I don't care if QLabel becomes longer than it was. I only care whether or not the main window will be expanded because of that.
You can use QFontMetrics to calculate the with of a text.
Hope it helps
Calculating width is no problem. But how can I know if the window will be expanded or not? The way I see it, I need to calculate the new width, and then ask the layout if setting this width will make it expand.
@Violet-Giraffe why not compare the label's width and the calculated width of the text?
I have addressed that in the last sentence of my question.