Solved QHBoxLayout does not resize when a child does, also other children keep their positions
-
Hi,
I want to put 2 or 3 labels inside a QHBoxLayout, then resize the first label using an animation.
I succeeded to do that, but sadly not as I expected.
The problem is that the layout doesn't auto resize to content when I change the first label width. Also, the other labels are not pushed or shifted to right.This is the result (Failed result):
I can do that in Java using JavaFX quite easily. So, I get that (Expected result):
This is my animation code:
QPropertyAnimation *animation = new QPropertyAnimation(ui->label_1, "size"); animation->setDuration(10000); animation->setStartValue(QSize(55, ui->label_1->size().height())); animation->setEndValue(QSize(600, ui->label_1->size().height())); animation->setEasingCurve(QEasingCurve::InCurve); animation->start();
NB: I'm using:
- Linux Mint
- Qt 5.15
- Qt ==> QHBoxLayout, QLabel
- JavaFX ==> HBox, Label
Thank you.
-
@Doros Please show how you're using layouts.
-
Yes, please show more. I guess you are not using layouts in the right way.
From what you posted, changing the "size" property of widgets in a layout is already wrong, that should be handled by the layout. -
-
I found a convenient solution, that I'm testing.
I handled the size of widgets by using strech property to one of them, then I put the layout it self inside an empty widget to let me to set width, because layout doesn't have a resizing property.I'm struggling now to continue my application.
Thanks both of you.