Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Problem: Stylesheet for QGroupBox



  • I have a QGridLayout with several QGroupBoxes. This is what one of these boxes looks like at the moment:
    0_1556533364650_I_have.png
    This is what I would like to have:
    0_1556533449607_I_want.jpg
    Three thing need to happen:

    1. Move the groupbox title upwards.
    2. Turn the groupbox title to blue.
    3. Reduce the horizontal padding between the contents of the text in order to take up less horizontal space.

    I have been using the setStyleSheet command, but with little success. Here is what I currently have:

    	containerWidget->setStyleSheet("QGroupBox { border: 1px solid blue;}");
    	containerWidget->setStyleSheet("QGroupBox::title {padding-top: -24px; padding-left: 8px;} ");
    
    

    Setting the second stylesheet undoes the first one. Then I tried this in one single instruction.

    containerWidget->setStyleSheet("QGroupBox { border: 1px solid blue;}"); QGroupBox::title { subcontrol-origin: margin; left: 7px; padding: 0px 5px 0px 5px;}");
    //your code here
    

    This does not work either.

    Any help will be highly appreciated.
    Kind regards, willem



  • @J.Hilk
    Merci beaucoup, JH, c'est parfait!
    wf


  • Moderators

    @willemf

    Et voilĂ  :

    containerWidget->setStyleSheet("QGroupBox{background-color: transparent; border: 1px solid blue; border-radius: 5px; margin-top: 3ex;} QGroupBox:title {subcontrol-position: top middle; padding: -14px 0px 0px 3px; color:blue;}");
    

    It's not exactly what you wan't but it's a working snipped from one of my projects ;-)



  • @J.Hilk
    Merci beaucoup, JH, c'est parfait!
    wf


Log in to reply