QLabel with wordWrap, fixed vertical policy and stretched for the whole QDialog's width fails to resize height
-
- Created a new project with QDialog as base class.
- Put QLabel on it.
- Added vertical layout to QDialog.
- Set
Vertical Policy
=Fixed
andwordWrap
=true
for QLabel. - Typed some text.
Seems like a bug to me because this behavior doesn't make any sense for such a trivial task as this one.
Or am I wrong?
-
Hi
But did you set a fixed size to the QLabel ? maximum width.
It seems to take all space it can get? -
But did you set a fixed size to the QLabel ?
QLabel
Horizontal Policy
=Preferred
Vertical Policy
=Fixed
maximum width.
Why would I want to set maximum width if I want it to be stretched for whole QDialog's width? And being able to resize the width along with QDialog.
It seems to take all space it can get?
Yeah, it gets all the horizontal space even after resizing QDialog.
P.s. it's annoying to wait 10 minutes for being able to reply back, lol.
-
Hi
But in the picture, there is still space left so and hence it won't word wrap. (yet)So im not sure I understand what is wrong then.
- P.s. it's annoying to wait 10 minutes for being able to reply back, lol.
Yes. Its spam prevention but yeah...
- P.s. it's annoying to wait 10 minutes for being able to reply back, lol.
-
But in the picture, there is still space left so and hence it won't word wrap. (yet)
That's the point. You just said how it was supposed to work. It shouldn't have done word wrapping since it didn't even hit the end and as you said there is still space left.
But in fact it does word wrapping.
No word wrapping:
Now it decides to make a new line (notice how height has changed):
Another new line:
And another one:
-
@Kelly-Ryan
Hi
It seems to work as expected here Qt 5.15
I followed your steps and I colored the Label green to be able to see its bounds.What Qt version are you seeing this ?
-
Oh, well, it's probably the case. I'm currently on 5.12.10. x)
I'm gonna try a bit later with updated version. -
I've downloaded 6.1.2 and it's the same.
Your label is not in QDialog but QMainWindow, I assume, 'cause of "Type Here" in the top left corner.Try to put a label in QDialog (even better if recreating step by step that I wrote in the first message) or if you want you can download my project:
https://mega.nz/file/91FlQapZ#TvAc0SAahkPxBRr_g3MJSo-Z3-dTMCKgwqh9EHB9rqg -
Hi
+1 for runnable project.Ah I think i missed the point that the odd thing happens while typing. not so much just running it with some text.
I agree that looks a bit buggy as why should it increase in size while typing.
I think it comes from its sizeHint
QSize QLabel::sizeHint() const { Q_D(const QLabel); if (!d->valid_hints) (void) QLabel::minimumSizeHint(); return d->sh; }
minimumSizeHint calls this
https://code.woboq.org/qt5/qtbase/src/widgets/widgets/qlabel.cpp.html#_ZNK13QLabelPrivate12sizeForWidthEithere it tries to find the longest word to use for word-break and I agree its a bit odd how it reacts while typing as those extra spaces
are not needed.So yes the calc seems a bit off.