It sounds like what you want is the left-aligned radio buttons to be centred inside the group box. You can do that using a horizontal layout containing three things:
- An expanding horizontal spacer
- A vertical layout containing the radio buttons (left aligned)
- An expanding horizontal spacer
Like this:
groupBox->setAlignment(Qt::AlignHCenter); // title alignment only
vLayout->addWidget(rb1);
vLayout->addWidget(rb2);
hLayout->addLayout(vLayout);
groupBox->setLayout(hLayout);
QGroupBox *groupBox = new QGroupBox("Group", this);
groupBox->setAlignment(Qt::AlignHCenter); // title alignment only
QRadioButton *rb1 = new QRadioButton("Radio", this);
QRadioButton *rb2 = new QRadioButton("Another radio", this);
QVBoxLayout *vLayout = new QVBoxLayout;
vLayout->addWidget(rb1);
vLayout->addWidget(rb2);
QHBoxLayout *hLayout = new QHBoxLayout;
hLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding) );
hLayout->addLayout(vLayout);
hLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding) );
groupBox->setLayout(hLayout);
To copy to clipboard, switch view to plain text mode
Also the the group box does not get centred and the borders not shown.
Centred in what? Setting the title alignment does not affect the placement of the group box itself. You can use the same technique as above to centre the group box in a containing layout if that is what you mean.
The absence or otherwise of the group box border is driven by the style in use, which varies from platform to platform by default. You can use style sheets to adjust the appearance of different widgets.
Bookmarks