QPushButton的checked和pressed样式设置无效是因为优先级问题

设置QPushButton想要设置pressed状态的图标,但是尝试了很多次都没有效果,原来是按照优先级来的,位置越往下优先级越高,hover状态时在最下面,所以鼠标在按钮上时,hover优先级最高,所以无论pressed还是checked都无法显示正确的图标,所以要调整下顺序;

 

QPushButton
{
    border-image:url(:/analysisCenter/Resources/analysisCenter/trianglenormal.svg);
}
QPushButton:checked
{
    border-image:url(:/analysisCenter/Resources/analysisCenter/triangleselect.svg);
}
QPushButton:pressed
{
    border-image:url(:/analysisCenter/Resources/analysisCenter/triangleselect.svg);
}
QPushButton:hover
{
    border-image:url(:/analysisCenter/Resources/analysisCenter/trianglehover.svg);
}
 

调整顺序如下,将hover上移:

QPushButton
{
    border-image:url(:/analysisCenter/Resources/analysisCenter/trianglenormal.svg);
}
QPushButton:hover
{
    border-image:url(:/analysisCenter/Resources/analysisCenter/trianglehover.svg);
}
QPushButton:checked
{
    border-image:url(:/analysisCenter/Resources/analysisCenter/triangleselect.svg);
}
QPushButton:pressed
{
    border-image:url(:/analysisCenter/Resources/analysisCenter/triangleselect.svg);
}

 

posted @ 2024-07-09 14:29  一字千金  阅读(150)  评论(0编辑  收藏  举报