How to change pushbutton color as well as keep the original mouse-hovered behaviour ?[Solved]
-
I am using Qt 4.8.0
When we create a pushbutton, it assumes a default gradient grey color. Also, on mouse-hover, it shows a gradient blue color.
I want to keep similar behaviour, but only change the colors.For example, I want a pushbutton to normally appear in gradient blue color, and on mouse-hover, the color should change to gradient yellow color.
I tried using qpalette for this, but was unsuccessful. Using stylesheet I was partially successful, but could not set mouse-hovered color
Any help is greatly appreciated.
Thank You
vivek -
Hello,
this style sheet code should help, if I understood correctly what you want to do. It has a QLinearGradient in blue, with red on hover.
It's a little modified example from Documentation.
Cheers@
QPushButton {
background: qlineargradient(x1:0, y1:1, x2:1, y2:1,
stop:0 white, stop: 0.4 blue, stop:1 white)
}QPushButton:hover{
background: qlineargradient(x1:0, y1:1, x2:1, y2:1,
stop:0 white, stop: 0.4 red, stop:1 white)
}
@[quote author="vivek.narvekar" date="1331816005"]I am using Qt 4.8.0
When we create a pushbutton, it assumes a default gradient grey color. Also, on mouse-hover, it shows a gradient blue color.
I want to keep similar behaviour, but only change the colors.For example, I want a pushbutton to normally appear in gradient blue color, and on mouse-hover, the color should change to gradient yellow color.
I tried using qpalette for this, but was unsuccessful. Using stylesheet I was partially successful, but could not set mouse-hovered color
Any help is greatly appreciated.
Thank You
vivek[/quote]
-
Hello g.lex,
Thanks a lot for the useful information.
It does work.
But the only thing is that the transition in the color (when the mouse is hovered) is not as smooth as that happens for the default color settings. ie the color changes abruptly from blue gradient to red gradient when the mouse is hovered. Any settings for this ?
Thanks a lot for help
Regards
Vivek -
Thanks Andre for the information.
In that case, I think I should better keep default behaviour, since I was planning to do this for all the widgets, starting with push button
-
For these kinds of customizations, that include animations, the Qt Widgets system is not all that suitable. A lot is possible, but it is not easy to do. If you want a customized UI like that contains animations, you should considder QML, perhaps in conjunction with the Desktop Components.
-
Actually we are migrating from a very old version of Qt (3.0.4) to Qt(4.8.0). So, along the course, i am trying to use new features provided by Qt, which can be quickly implemented without major change in existing code structure.