Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QHBoxLayout does not resize when a child does, also other children keep their positions
Doros last edited by Doros
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
@Doros Please show how you're using layouts.
Bonnie last edited by Bonnie
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.
Doros last edited by
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.