Results 1 to 6 of 6

Thread: QTabBar and different background color

  1. #1

    Default QTabBar and different background color

    I want change color all tab different color, but i dont find the solution.
    I try overload the class QTabBar and QTabWidget, but its not possible? paintEvent have some private class and variables...

    I have idea overload the QTabBar::initStyleOption, add here only one line to change background color for tab index, but this function its not VIRTUAL

    qt 4.5.1

    Any idea?

    Sorry for english

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QTabBar and different background color

    No need to subclass anything.
    Just use QPalette.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3

    Default Re: QTabBar and different background color

    Quote Originally Posted by high_flyer View Post
    No need to subclass anything.
    Just use QPalette.
    Can you give me little example how to set background color only for second tab?

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QTabBar and different background color

    I didn't understand that you wanted each tab to have a different color, that is a different matter.

    Hmm... maybe you can work around it by setting an icon, and setting its size to the tab size...

    The other way (that I see) is to override the QTabBar:aintEvent() but you should know if you are up to it.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5

    Default Re: QTabBar and different background color

    my bad english..

    Quote Originally Posted by high_flyer View Post
    The other way (that I see) is to override the QTabBar:aintEvent() but you should know if you are up to it.
    tihs function use some a private member of private class... looks very hard... i think QTabBar not have good support for override

    Quote Originally Posted by high_flyer View Post
    Hmm... maybe you can work around it by setting an icon, and setting its size to the tab size....
    this is good idea, but here can be problem with translation support ( tr() ), i must use icon + text, .. i try this way, thx for help

  6. #6
    Join Date
    Sep 2011
    Location
    Portugal
    Posts
    25
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QTabBar and different background color

    I've tried to override paintEvent(), but without success so far.
    Was anyone able to do this?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.