View Full Version : Color Tabs
FoleyX90
30th April 2010, 20:27
Where (if possible) could I find documentation or reference to make different tabs different colors/styles?
tbscope
30th April 2010, 20:43
Here you go: http://doc.qt.nokia.com/4.6/stylesheet-examples.html#customizing-qtabwidget-and-qtabbar
Extra tip: each tab has a name, use that name in your stylesheet to style each tab differently.
FoleyX90
30th April 2010, 20:44
Oh my goodness. Someone actually replied to me. (I've posted 8 times on qtforum.org - never once received a reply) THANK YOU!
FoleyX90
30th April 2010, 20:46
Here you go: http://doc.qt.nokia.com/4.6/stylesheet-examples.html#customizing-qtabwidget-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?
FoleyX90
30th April 2010, 20:48
I have also tried: QTabBar::tab#tabPersonal and QTabBar::#tabPersonal
tbscope
30th April 2010, 20:52
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
steno
30th April 2010, 20:54
You could also extend QTabBar and override the paint event, then for each tab choose a different color to paint them with.
FoleyX90
30th April 2010, 20:54
Yea, I tried that but it didn't work. :( Maybe I'm just a lost cause.
FoleyX90
30th April 2010, 20:55
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.
FoleyX90
30th April 2010, 20:57
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?
tbscope
30th April 2010, 20:57
Can you try: QTabBar#tabPersonal::tab ?
FoleyX90
30th April 2010, 21:01
Can you try: QTabBar#tabPersonal::tab ?
QTabBar#tabPersonal::tab does not work :(
tbscope
30th April 2010, 21:02
And if that doesn't work, set a stylesheet for each tab separately.
Example: tabPersonal.setStyleSheet("...");
tabNotPersonal.setStyleSheet("...");
FoleyX90
30th April 2010, 21:03
I have also tried QWidget::tab#tabPersonal, QWidget#tabPersonal::tab etc.
steno
30th April 2010, 21:03
void MyTabBar::paintEvent(QPaintEvent *event)
{
QStylePainter painter(this);
QStyleOptionTab opt;
for(int i = 0;i < count();i++)
{
initStyleOption(&opt,i);
//Set some color on the opt
painter.drawcontrol(QStyle::CE_TabBarShape,opt);
//Set some text color
painter.drawControl(QStyle::CE_TabBarTabLabel,opt) ;
}
}
That is a short example that should work. Not sure cause thats from memory.
FoleyX90
30th April 2010, 21:03
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 :(
steno
30th April 2010, 21:09
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
tbscope
30th April 2010, 21:23
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
FoleyX90
30th April 2010, 21:27
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.
FoleyX90
30th April 2010, 21:46
How would i incorporate my newly defined class into my QTabWidget?
wow, no my approch requies some coding. Just load the ui file in code, and then set your own tabbar class on the tabwidget.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.