Regarding Layout Management
Hello All
I am trying to place below mentioned widgets on my main Window but they are not aligning properly PleaseHELP
Widgets
1.GroupBox
2.In that GroupBox 2 PushButtons & One TableWidget
Here is my code
- {
- connect(btnImport, SIGNAL(clicked()), this, SLOT(ImportCSVFile()));
- connect(btnExport, SIGNAL(clicked()), this, SLOT(ExportCSVFile()));
- mainLayout->addWidget(btnImport, 0, 0 , 1, 2);
- mainLayout->addWidget(btnExport, 0, 1, 1, 2);
- mainLayout->addWidget(table, 0, 1, 1, 2);
- mainLayout->setColumnStretch(0,300);
- mainLayout->setColumnStretch(1, 500);
- groupBox->setLayout(mainLayout);
- return groupBox;
- }
2 replies
The order you use the calls does not set parents properly.
Usually, I suggest to give the parent in the constructors:
The other possibility is to use the auto reparent feature of the layouts, but then, the parent of the layout must fit, which means the layout must have it’s parent before addWidget is called.
- groupBox->setLayout(mainLayout);
- mainLayout->addWidget(btnImport, 0, 0 , 1, 2);
- mainLayout->addWidget(btnExport, 0, 1, 1, 2);
- mainLayout->addWidget(table, 0, 1, 1, 2);
I don’t think that’s the problem. I always construct layouts that way, and have never had any problems. With Qt 3.x you could run into all kinds of problems if you didn’t do things in the right order, but with Qt 4.x it tends to just work, regardless of the order in which you create things and put them in the layouts.
I think the problem is with the arguments to addWidget. Looks like you are adding btnExport and table in exactly the same place, for example. And btnImport and btnExport are overlapping.
You must log in to post a reply. Not a member yet? Register here!



