Removing the title from a QGroupBox
Asked Answered
G

2

12

Is it possible to completely remove the title from a QGroupBox? If you just give it an empty title, the label where the title would be still takes up space. It looks like this:

enter image description here

But I want it to look like this instead:

enter image description here

I tried the following things without success:

  • Setting the title font size to zero
  • Giving the title a size of zero in the stylesheet via setStyleSheet("QGroupBox:title{ max-width: 0; max-height: 0; }");
  • Moving the title inside the box via setStyleSheet("QGroupBox:title{ subcontrol-position: center center;}")

Note: You might say that a group box without title is a use case for QFrame. The problem with this is that I want to mix groups/frames with and without title, but the frame has a different visual style than the group box. So if you could tell me how to make QFrame look like QGroupBox that would solve my problems too.

Gurney answered 21/4, 2017 at 18:50 Comment(0)
Z
2

What you see is a bug of the particular style you're using. This pretty much "works" without you having to do anything special on other common styles (e.g. Mac, Windows). If you insist on using the particular style in question, you'll have to patch it yourself and either copy the style into your project, or build entire Qt to have a fixed version.

Zoroastrianism answered 21/4, 2017 at 18:54 Comment(2)
Thanks! You're right, it only happens with the Fusion style. There is a bug report about it here from January 2015.Gurney
The same happens with the default style on KDE Plasma. Quite annoyingBroke
R
15

You could use:

setStyleSheet("QGroupBox{padding-top:15px; margin-top:-15px}")

enter image description here

Rondeau answered 21/4, 2017 at 19:29 Comment(1)
Thanks! That's a possible workaround for now. I only changed 15px to 1em to make it work on my system.Gurney
Z
2

What you see is a bug of the particular style you're using. This pretty much "works" without you having to do anything special on other common styles (e.g. Mac, Windows). If you insist on using the particular style in question, you'll have to patch it yourself and either copy the style into your project, or build entire Qt to have a fixed version.

Zoroastrianism answered 21/4, 2017 at 18:54 Comment(2)
Thanks! You're right, it only happens with the Fusion style. There is a bug report about it here from January 2015.Gurney
The same happens with the default style on KDE Plasma. Quite annoyingBroke

© 2022 - 2024 — McMap. All rights reserved.