Child widgets climbing on top of QGroupBox title
-
I have a
QVBoxLayout
which has twoQGroupBox
set to checkable. The layout inside the group box inQGridLayout
which then contains some child widgets. However, the child widgets are being drawn on top ofQGroupBox
title. i.e.The QGroupBox is styles as follows:
QWidget { background-color: white; } QWidget QGroupBox { margin: 10px; font-size: 11pt; border: 1px solid gray; } QWidget QGroupBox QWidget { font-size: 10pt; padding: 10px; }
In the outer vertical layout, they are added one after the other.
The output is something like this:
What is the remedy for this problem?
-
Hi
Are you sure you insert the child into the layout ?
Also, if you use NO stylesheets , they do it as expected?Just asking to find out what can be wrong.- Normally the childs will not override title.
-
But I do need to style all the child widgets and the title of the QGroupBox has to be styled as well i.e. bold, larger font size. How to correctly write the style sheet ?
Also, in my case, if I delete the "QGroupBox" portion of the style string, I get this:
-
@ajaxcrypto
Ok, so you also have a insertion bug of some sort. Works fine in Designer.For your other issue, you can alter top margin
and it looks more correct
-
The group box still does not look correct, the title is not centered vertically on the frame nor the button texts are fully visible. I have a child inside on of the group boxes as a
QTableWidget
, whose header texts inexplicably get cutoff from both vertical directions, when I put it inside group box with style sheets. -
@ajaxcrypto
Ok, but im not sure its bug as such.- the title is not centered vertically on the frame
Nor will it be. its how it draws it - nor the button texts are fully visible.
well i didnt make box big enough.
make sure to read
http://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qgroupboxAlso for the other issue. its all a matter of size and spaces. It will not automatically adjust widget size to text
so when you alter point size for the font, you will have to adjust default size in many cases.Note that Designer have a build in editor you can use to test with even if you dont use UI files in the app.
- the title is not centered vertically on the frame
-
A further issue from that link,
QGroupBox::title { font-size: 14pt; }
-> This does not work, the font size is still the default size for me. I need to specify it for the wholeQGroupBox
and then change it for all child widgets. -
So, apparently changing
QGroupBox QTableWidget QHeaderView::section
style selector to justQTableWidget QHeaderView::section
solves the header text cutoff issue for theQTableWidget
(even though it is inside aQGroupBox
).
I will be writing my own group box like widget instead, which doesn't look too daunting to recreate. Will re-post screenshots with the custom widget if possible. Should I mark this as solved? -
@ajaxcrypto said in Child widgets climbing on top of QGroupBox title:
I will be writing my own group box like widget instead, which doesn't look too daunting to recreate. Will re-post screenshots with the custom widget if possible. Should I mark this as solved?
Hi
Well if you mostly want the frame and caption from the groupbox then
a custom widget is pretty forward. You can use QStyle to draw frame etc.if no further attempts to fix stylesheet then yes, please do mark as solved. :)