PDA

View Full Version : QVBoxLayout vs Qlabel - resizing issue



migel
10th July 2011, 17:23
simple adding lable into QVBoxLayout layout does not resize label .


QLabel *label = new QLabel("test");
QVBoxLayout *layout = new QVBoxLayout;
QWidget *widget = new QWidget;
widget->setLayout(layout);
layout->addWidget(label);

But when I add QTabWidget it resizes just fine.

I have tried this scenario using Q Designer and works there.

I have tried changing different sizePolicy of the label and widget, no luck.

what I am doing wrong ??

ChrisW67
11th July 2011, 00:08
How are you determining that the label does not get resized?

#include <QtGui>
#include <QDebug>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

QWidget widget;
QVBoxLayout *layout = new QVBoxLayout;
QLabel *label = new QLabel("test");
layout->addWidget(label);
widget.setLayout(layout);

qDebug() << widget.size() << label->size();
widget.show();
qDebug() << widget.size() << label->size();
widget.resize(320, 200);
qDebug() << widget.size() << label->size();
return app.exec();
}

out:


QSize(640, 480) QSize(640, 480)
QSize(47, 39) QSize(25, 17)
QSize(320, 200) QSize(298, 178)

Some layout resizing is not done until the widget is displayed, but the label is resized.