Important: Please read the Qt Code of Conduct -

Change the spacing between the close button and the border

  • How to increase the spacing between the close button and the border of the tab?


    I'm using this example:

    But the close button is too close to the border of the tab for what I want to do, so I was wondering if it's possible to increase the spacing.

  • @Mr-Gisa
    Dunno, but have you tried QTabBar::tab:right with margin-right or padding-right?

  • @JonB said in Change the spacing between the close button and the border:


    It doesn't work, unfortunately

  • Anyone to help me with that?

  • @Mr-Gisa said in Change the spacing between the close button and the border:

    Anyone to help me with that?

    This is apparently caused by the QTabBar::tab:top section of the stylesheet, which is really the only one relevant to your example: apparently, tab:right (and all the other orientations) does nothing because the right in there seems to refer to the tab location (at the top/bottom/left/right of the widget; in Qt Creator these are referred to North/South/West/East in the tabPosition property).

    If you remove the QTabBar::tab:top section altogether you get the original layout:


    The QTabBar::tab:top section as defined in the example css file, gives the small spacing you are unsatisfied with.

    This can be reproduced by the following minimal stylesheet:

        QString style = "\
            QTabBar::tab:top {\
                margin-right: -1px;\
                padding: 5px 10px 5px 10px;\

    The result is:


    If instead, I use:

        QString style = "\
            QTabBar::tab:top {\
                margin-right: -10px;\
                margin-left: 10px;\
                padding: 5px 20px 5px 20px;\
            QTabBar::tab:top:first {\
                margin-left: 0px;\

    The result is like:


    So, playing with the settings in QTabBar::tab:top in addition to overriding certain of those settings for QTabBar::tab:top:first and/or QTabBar::tab:top:last (the first and last tabs), you can change the layout somewhat.

  • Thank you very much. ♥

Log in to reply