Page 1 of 2 12 LastLast
Results 1 to 20 of 21

Thread: Color Tabs

  1. #1
    Join Date
    Apr 2010
    Posts
    37
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Color Tabs

    Where (if possible) could I find documentation or reference to make different tabs different colors/styles?

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Color Tabs

    Here you go: http://doc.qt.nokia.com/4.6/styleshe...et-and-qtabbar

    Extra tip: each tab has a name, use that name in your stylesheet to style each tab differently.

  3. #3
    Join Date
    Apr 2010
    Posts
    37
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Color Tabs

    Oh my goodness. Someone actually replied to me. (I've posted 8 times on qtforum.org - never once received a reply) THANK YOU!

  4. #4
    Join Date
    Apr 2010
    Posts
    37
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Color Tabs

    Quote Originally Posted by tbscope View Post
    Here you go: http://doc.qt.nokia.com/4.6/styleshe...et-and-qtabbar

    Extra tip: each tab has a name, use that name in your stylesheet to style each tab differently.
    I'm not exactly sure what you mean by 'each tab has a name' - I try to style it like: QTabBar::tabPersonal{...} but that doesn't work. What am I doing wrong?

  5. #5
    Join Date
    Apr 2010
    Posts
    37
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Color Tabs

    I have also tried: QTabBar::tab#tabPersonal and QTabBar::#tabPersonal

  6. #6
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Color Tabs

    I don't use stylesheets that much, but try this:
    If your first tab has the name tabPersonal, do this:

    QTabBar::tab#tabPersonal {
    background: red;
    }

    The documentation says:
    ID Selector QPushButton#okButton Matches all QPushButton instances whose object name is okButton.
    So I guess it should work on QTabBar::tab too.
    http://doc.qt.nokia.com/4.6/stylesheet-syntax.html
    http://www.w3.org/TR/CSS2/selector.html#id-selectors

  7. #7
    Join Date
    Nov 2009
    Location
    Sacramento, CA
    Posts
    24
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Color Tabs

    You could also extend QTabBar and override the paint event, then for each tab choose a different color to paint them with.

  8. #8
    Join Date
    Apr 2010
    Posts
    37
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Color Tabs

    Yea, I tried that but it didn't work. Maybe I'm just a lost cause.

  9. #9
    Join Date
    Apr 2010
    Posts
    37
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Color Tabs

    Quote Originally Posted by FoleyX90 View Post
    Yea, I tried that but it didn't work. Maybe I'm just a lost cause.
    I tried the 'QTabBar::tab#tabPersonal {
    background: red;
    }' part.

  10. #10
    Join Date
    Apr 2010
    Posts
    37
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Color Tabs

    Quote Originally Posted by steno View Post
    You could also extend QTabBar and override the paint event, then for each tab choose a different color to paint them with.
    Hmm.. any tutorials or documentation on specifically extending QTabBar's paint event?

  11. #11
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Color Tabs

    Can you try: QTabBar#tabPersonal::tab ?

  12. #12
    Join Date
    Apr 2010
    Posts
    37
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Color Tabs

    Quote Originally Posted by tbscope View Post
    Can you try: QTabBar#tabPersonal::tab ?
    QTabBar#tabPersonal::tab does not work

  13. #13
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Color Tabs

    And if that doesn't work, set a stylesheet for each tab separately.

    Example: tabPersonal.setStyleSheet("...");
    tabNotPersonal.setStyleSheet("...");

  14. #14
    Join Date
    Apr 2010
    Posts
    37
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Color Tabs

    I have also tried QWidget::tab#tabPersonal, QWidget#tabPersonal::tab etc.

  15. #15
    Join Date
    Nov 2009
    Location
    Sacramento, CA
    Posts
    24
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Color Tabs

    Qt Code:
    1. void MyTabBar::paintEvent(QPaintEvent *event)
    2. {
    3. QStylePainter painter(this);
    4. for(int i = 0;i < count();i++)
    5. {
    6. initStyleOption(&opt,i);
    7. //Set some color on the opt
    8. painter.drawcontrol(QStyle::CE_TabBarShape,opt);
    9. //Set some text color
    10. painter.drawControl(QStyle::CE_TabBarTabLabel,opt);
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

    That is a short example that should work. Not sure cause thats from memory.

  16. #16
    Join Date
    Apr 2010
    Posts
    37
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Color Tabs

    Quote Originally Posted by tbscope View Post
    And if that doesn't work, set a stylesheet for each tab separately.

    Example: tabPersonal.setStyleSheet("...");
    tabNotPersonal.setStyleSheet("...");
    If you set a stylesheet in the actual tab, it just styles the content area inside the selected tab

  17. #17
    Join Date
    Nov 2009
    Location
    Sacramento, CA
    Posts
    24
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Color Tabs

    This link should also help you get started if you can't figure out the style sheet.

    http://doc.qt.nokia.com/4.6/style-reference.html#tabs

  18. #18
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Color Tabs

    Sorry, I tried but it seems I can't find the answer for the stylesheet approach.

    Best next thing to do is as Steno says, subclass and reimplement the paintevent

  19. #19
    Join Date
    Apr 2010
    Posts
    37
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Color Tabs

    Sorry, I may need my hand held through this. I've never really extended classes in Qt using Qt Creator - I wouldn't know how to add the extended class to my .ui file.

  20. #20
    Join Date
    Apr 2010
    Posts
    37
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Color Tabs

    How would i incorporate my newly defined class into my QTabWidget?

Similar Threads

  1. QTabBar color in space inbetween tabs
    By AwDogsgo2Heaven in forum Newbie
    Replies: 1
    Last Post: 12th March 2010, 08:44
  2. Replies: 3
    Last Post: 22nd January 2010, 16:46
  3. Display Label Color by selecting Color Picker
    By sosanjay in forum Qt Programming
    Replies: 1
    Last Post: 25th September 2009, 06:11
  4. how to change backgroup color, button color and shape?
    By lzha022 in forum Qt Programming
    Replies: 10
    Last Post: 16th June 2008, 22:25
  5. Changing QTabWidget's tabs color
    By troorl_ua in forum Qt Programming
    Replies: 1
    Last Post: 14th May 2007, 21:49

Tags for this Thread

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.