QSS按钮样式设置的坑,按下(pressed)时按钮颜色不变化

正确的设置:按钮颜色、disable后的颜色、按下的颜色

QPushButton:focus{outline: none;}
QPushButton
{
    color: white;
    border:hide;
    border-radius:2px;
    padding:0px 0px;
    background-color: rgb(51,51,51);
}
QPushButton:!enabled
{
    color: gray;
    border:hide;
    border-radius:2px;
    padding:0px 0px;
    background-color: rgb(100,100,100);
}
QPushButton:pressed
{
    background-color:rgb(200 , 200 , 200);
    padding-left:2px;
    padding-top:2px;
}

错误的设置:按钮颜色、enabled颜色、按下颜色

QPushButton:focus{outline: none;}
QPushButton
{
    color: gray;
    border:hide;
    border-radius:2px;
    padding:0px 0px;
    background-color: rgb(100,100,100);
}
QPushButton:enabled
{

color: white;
    border:hide;
    border-radius:2px;
    padding:0px 0px;
    background-color: rgb(51,51,51);
 }

QPushButton:pressed
{
    background-color:rgb(200 , 200 , 200);
    padding-left:2px;
    padding-top:2px;
}

会发现按钮按下时,颜色不会发生变化,原因时enabled状态优先级更高。


版权声明:本文为Sparrow_du原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。