PDA

View Full Version : QVBoxLayout to center



seltra
7th October 2010, 17:05
when i use the code below, Qt puts labels on the right side.
How can i put labels centered in the line?



myproject::myproject(QWidget *parent, Qt::WFlags flags): QMainWindow(parent, flags)
{
ui.setupUi(this);

QVBoxLayout *mainlayout = new QVBoxLayout;
QLabel *label1= new QLabel("aaa");
QLabel *label2= new QLabel("bbb");
QLabel *label3= new QLabel("cccc");
QLabel *label4= new QLabel("ddd");
mainlayout->addWidget(label1);
mainlayout->addWidget(label2);
mainlayout->addWidget(label3);
mainlayout->addWidget(label4);
ui.centralWidget->setLayout(mainlayout);


}

tbscope
7th October 2010, 17:19
Try:
http://doc.qt.nokia.com/latest/qlayout.html#setAlignment

seltra
7th October 2010, 18:23
thank you tbscope. it worked.