Child widgets climbing on top of QGroupBox title



  • I have a QVBoxLayout which has two QGroupBox set to checkable. The layout inside the group box in QGridLayout which then contains some child widgets. However, the child widgets are being drawn on top of QGroupBox 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:
    0_1505324773676_qgroupbox.png

    What is the remedy for this problem?


  • Qt Champions 2016

    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.


  • Qt Champions 2016

    update
    Ok, it is your stylesheet:)
    alt text

    (no sheet)
    alt text



  • 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:

    0_1505325495832_qgb1.png


  • Qt Champions 2016

    @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
    alt text
    and it looks more correct
    alt text



  • 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.


  • Qt Champions 2016

    @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.
      alt text

    make sure to read
    http://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qgroupbox

    Also 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.



  • 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 whole QGroupBox and then change it for all child widgets.



  • So, apparently changing QGroupBox QTableWidget QHeaderView::section style selector to just QTableWidget QHeaderView::section solves the header text cutoff issue for the QTableWidget (even though it is inside a QGroupBox).
    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?


  • Qt Champions 2016

    @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. :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.