Dear visitor, welcome to QtForum.org.
If this is your first visit here, please read the Help. It explains in detail how this page works.
To use all features of this page, you should consider registering.
Please use the registration form, to register here or read more information about the registration process.
If you are already registered, please login here.
QVBoxLayout to center
when i use the code below, Qt puts labels on the right side.
How can i put labels centered in the line?
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
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);
}
|
You only have to do the following:
|
Source code
|
1
|
mainlayout->addWidget(label1, Qt::AlignCenter);
|
for all of your labels.
Hope this helps.
unfortunately it didn't work.
this has worked.
thank you very much.
|
Source code
|
1
|
mainlayout->setAlignment(Qt::AlignCenter);
|