Set the vertical sizepolicy of your label to QSizePolicy::Minimum
.
Then set the sizeconstraint of your dialog's layout to QLayout::SetMinimumSize
.
This should make your dialog grow so all the content will fit inside of it.
Something like this:
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. This is a very long text. This is a very long text. "
"This is a very long text. This is a very long text. This is a very long text. This is a very long text. "
"This is a very long text. This is a very long text.");
layout->addWidget(label);
}