Qt StyleSheet Text Alignment

Atilla Baspinar picture Atilla Baspinar · Sep 23, 2013 · Viewed 10.8k times · Source

I am trying to change the appearance of a QGroupbox. The problem is about the border of it. After changing the style sheet, the text of the groupbox is not aligned with the border anymore. How can this be solved?

In the first picture, the border is well aligned with the text:

The style sheet related to this QGroupBox is like this:

QGroupBox{
background-color: rgb(0,80,120);
color: white;
font: 14pt "MS Shell Dlg 2";
font: bold;
text-align:center;
}

In the second picture, the border is aligned with the bottom of the text:

The style sheet related to QGroupBox above is like this:

QGroupBox{
background-color: rgb(0,80,120);
color: white;
font: 14pt "MS Shell Dlg 2";
font: bold;
text-align:center;
border-color: rgb(255,255,255);
border-width: 2px;
border-style: solid;
border-radius: 9px;
padding: 2px;
}

As you can see, when I add border related parameters, text alignment somehow changes. I want the first style but with the text aligned properly with the border. What is wrong?

Thanks.

Answer

Dmitry Sazonov picture Dmitry Sazonov · Sep 23, 2013

Nothing wrong. But you should adjust margin / padding. And sub controls. I propose you to read Qt stylesheet reference.