Solved change the size of a widget
-
greetings to everyone,
I have a problem that I can't solve, here's the problem: I have a widget(container) that contains a label to display the text but I want to make the size of the widget(container) vary according to the number of characters in the label -
-
This post is deleted! -
@mrjj Thank you for your answer but except that the code provided in the link you gave me just varies the size of the widget vertically but I want the size of the widget to vary vertically and also horizontally.
Thank you in advance.
-
@EL-jos
ok, did u try with 2x QSizePolicy::MinimumExpanding ? -
@mrjj still nothing the size does not vary horizontally
Here's my code maybe I misspelled it:QVBoxLayout *layout = new QVBoxLayout; layout->setSizeConstraint(QLayout::SetMinimumSize); this->setLayout(layout); for(int i = 0; i < 5; i++) { QLabel *label = new QLabel; label->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); label->setWordWrap(true); label->setText("This is a very long text. "); layout->addWidget(label); }
I even reduced the number of characters to see if it works.
-
Can someone help me, please?
-
@EL-jos
did you try with
label->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); -
Hello @mrjj
Yeah, it's working fine now.
Thank you very much for your help.