Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTabWidget style sheet

QTabWidget style sheet

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 6.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    GrahamL
    wrote on last edited by
    #1

    Hi
    I have a style sheet for QTabWidget and QTabBar that looks ok except that I cannot figure out how to make the tab width dependant on the text that it is displaying. Currently I have this as a fixed value but when I add a new tab with a wider label I have to adjust the style sheet.
    Is there a way of doing this dynamically?

    here is my style sheet
    @
    QTabWidget, QStackedWidget
    {
    background: none
    }
    QTabWidget QWidget
    {
    background-color: lightblue;
    }

    QTabWidget::pane
    {
    border: 0px;
    top: 0.1em;
    border-image: url(tabBG.png);
    border-width: 1px;
    border-style: solid;
    border-color: grey;
    }
    QTabBar::tab
    {
    width: 120px;
    margin-left: 0.5;

    margin-right: 0.5;
    
     border: 1px solid #7a7a7a;
    
     border-top-left-radius: 4px;
    border-top-right-radius: 4px;
    padding: 2px 6px 2px 6px;
    

    }

    QTabBar::tab:!selected {
    margin-top: 2px;
    }
    QTabBar::tab:selected {
    margin-top: -1px;
    background-color: lightblue;
    borderwidth: 0px;
    }

    QTabBar::tab::bottom
    {
    border-bottom-left-radius: 4px;
    border-bottom-right-radius: 4px;
    border-top-left-radius: 0px;
    border-top-right-radius: 0px;
    padding: 2px 6px 2px 6px;
    }
    @

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tilsitt
      wrote on last edited by
      #2

      Hi,

      I am not sure you could achieve your goal using style sheets. I think reimplementing one of the methods used by Qt to compute the size of each widget and return a size based on the QTabBar text could do the trick (e.g. sizeHint or minimumSizeHint).

      1 Reply Last reply
      0
      • R Offline
        R Offline
        ray4qt
        wrote on last edited by
        #3

        By setting a width for the tabs I believe they will be fixed at that width, preventing them from adjusting automatically to fit the text.

        @QTabBar::tab
        {
        width: 120px;@

        As a suggestion, try commenting out that line and see what happens.

        You can of course use the min-width property if you want, well, a minimum width.

        Just a thought.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved