transition in QPushButton change from normal to hover and pressed:
-
hi I'm using Qt Creator and Stylesheet of my QPushButton looks like this:
QPushButton { border: 1px solid rgb(24, 103, 155); border-radius: 5px; background-color: rgb(124, 203, 255); } QPushButton:hover { border: 1px solid rgb(24, 103, 155); border-radius: 5px; background-color: rgb(79, 176, 240); } QPushButton:pressed { border: 1px solid rgb(24, 103, 155); border-radius: 5px; background-color: rgb(20, 153, 240); }
but now I want it to gradually change colors to hover or pressed like in half a second. how do i do that?
-
hi I'm using Qt Creator and Stylesheet of my QPushButton looks like this:
QPushButton { border: 1px solid rgb(24, 103, 155); border-radius: 5px; background-color: rgb(124, 203, 255); } QPushButton:hover { border: 1px solid rgb(24, 103, 155); border-radius: 5px; background-color: rgb(79, 176, 240); } QPushButton:pressed { border: 1px solid rgb(24, 103, 155); border-radius: 5px; background-color: rgb(20, 153, 240); }
but now I want it to gradually change colors to hover or pressed like in half a second. how do i do that?
@nullbuil7 said in transition in QPushButton change from normal to hover and pressed::
in half a second
Please explain.
Stylesheets have no time based functions. If you want to change the stylesheet half a second later after you hovered your button, you will need to do that with some
QTimer
.transition in QPushButton change from normal to hover and pressed
There is no real "transition". You could theoretically hover your cursor over one button for years without clicking it.
Click
andHover
are two independent actions. Ok, your cursor needs to be inside your button's rect in order to click, which is some "hovering"...So start the
QTimer
when your mouse enters your button and then adjust your stylesheet or start someQPropertyAnimation