Important: Please read the Qt Code of Conduct -

How to get all the tabs on left or right of the selected tabs using CSS?

  • Hi all,

    All my question is in the title :)

    Thanks in advance for your help.

  • Moderators

    I don't know that you can get that specific with CSS, but I'm sure if someone knows an answer they'll post it. If so, I'd be interested in seeing how, myself.

  • Well, QSS allows you to set any property on the widgets you're styling. That includes setting the orientation, I'd think.

  • Of course I already had a look at the reference.
    The thing is QTabBar::tab:selected and QTabBar::tab:!selected allows you to modify the properties of selected and non-selected tabs, QTabBar::tab:next-selected and QTabBar::tab:previous-selected allows you to modify the properties of tabs closed to the selected tab.
    So I wonder if there is a trick to modify the properties of all the tabs on left or right of the selected tab.

  • [quote author="KA51O" date="1330499953"]Did you already had a look at "this": ?[/quote]

    Did you? Where in there is there an example of the feature that tomuse asked for?

    Did you spot this:
    I checked the Qt source, and QTabWidget::tabPosition is such a property. That means it is stylable using the syntax above.

  • Well basically all tabs on the left and right of the selected tab are all tabs except the selected...
    so you can set the settings for all tabs the way you want and have a special look for the selected, or am I missing something ?

    Edit: Ok I get it, you just want the ones on the left OR the ones on the right... Sorry I missread that.
    Maybe you can do this by looping over your tabWidget and for each tab left of the selected(i.e. index smaller than the index of the selected tab) set a special style.

  • Could be a solution but I guess I cannot do this directly in a CSS file...

  • Ah, well, actually, I misunderstood. I thought the question was to change where the tabs would appear: to the left (west), to the right (east) on the top (north) or on the bottom (south) of the widget using CSS. However, the question was how to differently style the different tabs to the left of the current tab than the ones to the right. That is a different question. Again, sorry, I misread the question.

    I don't think that that is possible, at least not without a lot of trickery. There is no property you can use to style on. The only hack I can come up with, is to use a proxy style and abuse a property you can use (enabled comes to mind) from the proxy. Basically, you would modfy the style option to say that any tab to the left of your current one is disabled using a QProxyStyle subclass. Then, you can use CSS to render the disabled ones (left ones) differently than the other tabs. Because the tabs are not really disabled, the tabwidget would still work as normal. Obviously, if you really have disabled tabs, this won't work, and I'm not sure the approach will work at all.

    Edit: because tabs are not widgets, I don't think you can set a style per-tab.

  • Thanks for your answer Andre.
    I also thought about a QProxyStyle, but too tricky :)
    I'll settle for applying the same style for all the non-selected tabs.

    Thanks for your help guys!

  • bq. Edit: because tabs are not widgets, I don’t think you can set a style per-tab.

    I think you could do it, but one would have to reimplement QTabWidget and QTabBar to have your own handling for the currentChanged() signal in QTabBar where one would then first get the tabButton using QTabBar::tabButton(int index, ButtonPosition position ) to get the single tabButton widgets and set the desired styles for them. The custom QTabBar must be set as the tabbar of the custom QTabWidget.

  • I think the tabButton is something different: it is a button you can put on the tab (usually to close it). It is not the tab itself, but I might be off here... AFAIK, the tabs themselves are not buttons, but are rendered directly by the style using QStyle::drawControl and the CE_TabBarTab flag.

  • Hmm, you may be right.

Log in to reply