How can I set background color/image specific tab at QTabWidget?



  • Hi to everyone!
    After the long visitor status, finally, this is my first post.
    I create tabs dynamically in my TabWidget(from config). Like;
    -it is python code, pyqt, answers can be coded c++, dosn't matter for me :) -

    @baseWidget = QWidget()
    //fill baseWidget with other widgets
    window.tabWidget.addTab(baseWidget, _fromUtf8(""))
    window.tabWidget.setTabText(window.tabWidget.indexOf(baseWidget), ...)@

    Then, style via qss, like;

    @QTabBar::tab {}
    QTabBar::tab:selected {}
    QTabBar::tab:!selected {}
    QTabBar::tab:last {}
    QTabBar::tab:first:!selected {}
    QTabBar::tab:!selected:hover {}@

    At this point everything is OK. But, i want to colorize my tabs individually.

    How can i achieve this?
    If it is possible, how can set objectName for a tab?

    All post will be appreciated :)





  • You can use class name as id (#) in css.

    for example:
    @QWidget#ozelterTab { background: orange; }
    QWidget#gunlukAnalizTab { backgroud: blue; }
    ...@

    I saw it once in an example. It worked there, but never tried it myself.



  • [quote author="Jake007" date="1356614068"]You can use class name as id (#) in css.

    for example:
    @QWidget#ozelterTab { background: orange; }
    QWidget#gunlukAnalizTab { backgroud: blue; }
    ...@

    I saw it once in an example. It worked there, but never tried it myself.[/quote]

    I use # selector for other widgets, if i am able to set objectName.
    But here i cant set an objectName for individual tab !

    i tried ,
    @basewidget.setObjectName("blablabla")
    @
    didn't work :(



  • Is it possible via subclassing QTabBar or QTabWidget ?



  • Anyone here ???



  • That's not possible out of the box.

    And immediate solution the springs to mind is to provide a QProxyStyle, which draws the tabs the way you like it (you will need a custom drawing method anyways for the style you want).



  • First, thanks for your reply Lukas, i was really on tenterhooks

    1-) can i say that it is imppossible with qss ?
    2-) out of style, how i achieve to point a random tab for other purposes ?
    3-) and most important, where can i find a extensive proxymodel example ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.