QHBoxLayout widget spacing
Can't seem to get widgets in a layout spaced the way I want.
Code:
// panel_1 class
int w = 50;
int h = 100;
layout_1->setSpacing(0);
layout_1->addWidget(pbStart);
lineEdit1->setFixedSize(w, h);
lineEdit2->setFixedSize(w, h);
lineEdit3->setFixedSize(w, h);
layout_1->addWidget(lineEdit1);
layout_1->addWidget(lineEdit2);
layout_1->addWidget(lineEdit3);
// mainwindow class
layout->setSpacing(1);
panel_1 = new Panel_1();
layout->addWidget(panel_1);
layout->addWidget(d_.view);
widget->setLayout(layout);
setCentralWidget(widget);
The space between the pb and the line edits and between the edits is constant - about 2"
Checking spacing() with debug, it reports 0.
What am I doing wrong that's not letting me set the spacing to what I need?
Thanks for any help.
Re: QHBoxLayout widget spacing
I guess you hou have four fixed width widgets in a horizontal layout that is wider than the four widgets so the layout engine distributes the spare space evenly. Try adding the widgets to the layout with the alignment option of addWidget() specified.
Re: QHBoxLayout widget spacing
Thanks Chris, using the alignment option when adding the widget solves the problem.