Set backgroud color and Mouse hover highlighting for tabs ?[solved]
-
Hello,
I want to set color for the tabbar buttons. I tried using stylesheets, but, when we set stylesheet for tabbar, it is considered for the whole tabbar, and not for the individual tab button, hence, when I do mouse-hover, then entire tab bar is highlighted and not the individual tab button.
Details of the code-
I have overridden the enterevent for tabbar and written following code
@setStyleSheet("QTabBar {
background: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, stop:0 rgba(255, 255, 255, 255), stop:1 rgba(255, 246, 143, 255));
color: rgb(0, 0, 255);
}
"); // for setting gradient yellow color @Then, I have overriden the leaveenvt and written following code
@setStyleSheet("QTabBar {
background: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, stop:0 rgba(255, 255, 255, 255), stop:1 rgba(200, 226, 240, 255));
color: rgb(0, 0, 255);
}
"); // for setting gradient yellow color @Thus, this gives an effect of mouse hover, ie when the mouse enter, it turns tabbar into gradient yellow, and when the mouse leave, it turns tabbar to gradient blue.
But actually, what i want is the individual tab button to change the color, and not the entire tab bar, as is happening in the above case.Thanks for any help.
Regards
Vivek -
this should be possible using only stylesheets, eliminating the need for subclassing the tabwidget. However, you have to alter the stylesheet slightly:
@
QTabBar::tab {
// add normal style here
}QTabBar::tab:hover {
// add mouse hover style here
}
@see also "here":http://qt-project.org/doc/qt-4.8/stylesheet-examples.html#customizing-qtabwidget-and-qtabbar
-
Thank you very much, I tried your solution and it worked perfectly :)
I was referring http://qt-project.org/doc/qt-4.8/stylesheet-syntax.html for stylesheet syntax, but did not find anything related to tab. can you please let me know, where to search for stylesheet syntax, since I face such issues many times...
Thanks a lot for helping...
-
The link I've posted ("this one":http://qt-project.org/doc/qt-4.8/stylesheet-examples.html) has several examples on how to use stylesheets for the differet Qt widget classes.
If you're looking for general stylesheet syntax and examples, maybe "this":http://www.w3schools.com/css/ will be useful to you :) -
Thanks a lot.. This was very useful .. :)