Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QTabBar tab size doesn't scale with stylesheet font

I have the following stylesheet:

QTabBar::tab {

background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,
                        stop: 0 #2A2A2A, stop: 0.4 #E1E1E1,
                        stop: 0.5 #E1E1E1, stop: 1.0 #2A2A2A);
background-image: url(:/metal_toolbar);
border-left: 1px solid #9B9B9B;
border-right: 1px solid #9B9B9B;
border-bottom: 1px solid #9B9B9B;
border-top-color: #5A5A5A;
font: bold 12pt;
/*min-width: 20ex;
max-width: 1000ex;*/
padding: 2px;
}

If I don't declare the font in the style sheet, my tabs are sized appropriately for the text they contain, however when I increase the font size, the tab size remains constant and the text gets cut-off. I've tried all the width settings but I want the tab width to scale to what it contains.

Anyone know a work-around or fix for this?

I'm loading the style sheet file into my program as a skin, so I'd prefer stylesheet solutions over programmatic solutions if they exist

EDIT:

Here's the working version with proper tab sizes

QTabBar
{
    font: bold 9pt;
}

 QTabBar::tab 
 {

    background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,
                            stop: 0 #2A2A2A, stop: 0.4 #E1E1E1,
                            stop: 0.5 #E1E1E1, stop: 1.0 #2A2A2A);
    background-image: url(:/metal_toolbar);
    border-left: 1px solid #9B9B9B;
    border-right: 1px solid #9B9B9B;
    border-bottom: 1px solid #9B9B9B;
    border-top-color: #5A5A5A;
    min-width: 20ex;
    padding: 2px;
 }
like image 743
Nicolas Holthaus Avatar asked Nov 01 '22 16:11

Nicolas Holthaus


1 Answers

Set the font from the QTabBar then. Rough pseudocode below.

font = tabbar.font()
font.setPointSize(12)
font.setBold(true)
tabbar.setFont(font)

You should be able to access the QTabBar from the QTabWidget, and just set your style sheet without the font. I hope this can help.

like image 173
justengel Avatar answered Nov 15 '22 03:11

justengel