Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Hover and Pressed stylesheet Qt

I used this in my button pushButton 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 color, like I expect it to , But the hover color remains even when I press the button. I tried changing the order, but its still the same problem . little new in Qt.

like image 607
harveyslash Avatar asked Oct 03 '13 13:10

harveyslash


2 Answers

You can combine states, for example:

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

QSS reference - states

like image 162
Dmitry Sazonov Avatar answered Oct 30 '22 13:10

Dmitry Sazonov


Css, and Qt CSS, depends on the order of declarations. Later declarations with the same specificity will overwrite previous declarations. So, in order to have the pressed state take precedence, simply move it below the hover state.

QPushButton#pushButton {
    background-color: yellow;
}

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

QPushButton#pushButton:pressed {
    background-color: rgb(224, 0, 0);     
}
like image 38
mflodin Avatar answered Oct 30 '22 12:10

mflodin