Reputation: 2053
I have a widget with groupbox. I set the border for the groupbox using stylesheet that also works fine, but the border is not fit with the groupbox title. I searched in google, they suggest to change the groupbox title like:
QGroupBox::title {
background-color: transparent;
subcontrol-position: top left; /* position at the top left*/
padding: 2px 13px;
}
In my code i used the stylesheet like:
ui->groupBox->setStyleSheet("border: 1px solid gray;"
"border-radius: 9px;"
"margin-top: 0.5em;");
so how to apply setstylesheet property for the groupbox title, guide me.
Upvotes: 1
Views: 13260
Reputation: 741
Apply such stylesheet to parent of groupBox
:
this->setStyleSheet("QGroupBox::title {"
"background-color: transparent;"
"padding-top: -24px;"
"padding-left: 8px;} ");
In my case it was MainWindow
.
Also you can edit stylesheet from QtDesigner by calling "Edit styleSheet..." menu on required widget. I prefer to edit my MainWindow
stylesheet to keep all code in one place.
In QtDesigner CSS will looks like this (this is stylesheet of QGroupBox
parent):
QGroupBox {
border: 1px solid gray;
border-radius: 9px;
margin-top: 0.5em;
}
QGroupBox::title {
background-color: transparent;
padding-top: -24px;
padding-left: 8px;
}
Upvotes: 5