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); }
自己开发了一个股票智能分析软件,功能很强大,需要的关注微信公众号:QStockView