qtqtstylesheetsqpushbutton

How to set a custom stylesheet for hover and pressed states


I used this as my button pushButton's stylesheet:

QPushButton#pushButton {
    background-color: yellow;
}
QPushButton#pushButton:pressed {
    background-color: rgb(224, 0, 0);     
}
QPushButton#pushButton:hover {
   background-color: rgb(224, 255, 0);
}

When I hover my mouse over it, it changes its color, like I expect it to, but the hover color remains even when I press the button.

I tried changing the order, but It's still the same problem.


Solution

  • You can combine states, for example:

    QPushButton:hover:!pressed
    {
      border: 1px solid red;
    }
    

    QSS reference — states