@PLL3 said in Issue with QLabel and wordwrap:
Out of curiosity I tried it, and it had the same result as adding a spacer item after my QLabel, ie it squishes it to the left and forces it to wrap as much as it can.
Yes, as the example code I posted above, I met this problem exactly when I'm using alignment in layout :)
@PLL3 said in Issue with QLabel and wordwrap:
QRect boundingRect1 = fm.boundingRect(_label->rect(), _label->alignment(), _label->text());
Oh, flags is not the same as alignment, the way you call it still doesn't tell that you want text to wrap.
So here it should be something like fm.boundingRect(_label->contentsRect(), _label->alignment() | Qt::TextWordWrap, _label->text())
contentsRect() is still not the exact rect value that Qt use to draw text. If you want to more accurate you can check the Qt source code of QLabel::paintEvent, but maybe not very necessary.