The snippet below illustrates the problem. I have a QVBoxLayout for which I've set the Alignment to AlignCenter. I've then added two labels to it. The first label is properly centered, but only because it is within it's own HBoxLayout, for which AlignCenter is set.
// Vertical Box Layout
wlogVB_cLL->setAlignment(Qt::AlignCenter);
// FIRST item
wlogHB_dLL->setAlignment(Qt::AlignCenter);
laWellLL->setText("First");
wlogHB_dLL->addWidget(laWellLL);
wlogVB_cLL->addLayout(wlogHB_dLL);
// SECOND item
laWellLL2->setText("Second");
wlogVB_cLL->addWidget(laWellLL2);
// Additional items, some of which are in HBoxLayouts
// Vertical Box Layout
QVBoxLayout *wlogVB_cLL = new QVBoxLayout;
wlogVB_cLL->setAlignment(Qt::AlignCenter);
// FIRST item
QHBoxLayout *wlogHB_dLL = new QHBoxLayout;
wlogHB_dLL->setAlignment(Qt::AlignCenter);
QLabel *laWellLL = new QLabel;
laWellLL->setText("First");
wlogHB_dLL->addWidget(laWellLL);
wlogVB_cLL->addLayout(wlogHB_dLL);
// SECOND item
QLabel *laWellLL2 = new QLabel;
laWellLL2->setText("Second");
wlogVB_cLL->addWidget(laWellLL2);
// Additional items, some of which are in HBoxLayouts
To copy to clipboard, switch view to plain text mode
The second label, however: it is Aligned to the left... despite the fact that I set the *vertical* box layout to be AlignCenter. The only way I can get it to align center: put it in an HBoxLayout, just like "first".
Perhaps this is the way it's supposed to work... though I don't understand why.
My guess (I can't test it at the moment): if the VBoxLayout *only* had widgets, the setAlignment(Qt::AlignCenter) would work. But because it contains a mix of widgets and layouts, it doesn't work... and therefore *all* of the widgets must be contained in an HBoxLayout, each of which has alignment set to Center.
Bookmarks