Change icon on state change using Qt stylesheet

纵饮孤独 提交于 2019-12-02 04:14:11

Setting qApp.style() is not a good idea. Try this (convert from C++):

button->style()->unpolish(button);
button->style()->polish(button);
button->update();

Figured it out. I kept the icons on my form so that I knew which icons went to which one, but in my stylesheet, I did something like this:

QPushButton#searchNext {
    qproperty-icon: none;
    image: url(":/light/icons/down_light.png"); 
}

Then on my hover:

QPushButton#searchNext:hover {
    image: url(":/dark/icons/down_dark.png");   
}

I still needed the self.ui.playButton.setStyle(qApp.style()) code when I change a custom property, but for everything else, this works fine.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!