我在 S60 Qt 应用程序中使用 QPushButton。
我希望按钮图标在获得焦点时发生变化。
我试过这个...
navButton->setStyleSheet("background-image: url(c:/Data/navArrowsNotSelected.png);");
setStyleSheet("DoubleViewWidget QPushButton:focus {background-image: url(c:/Data/navArrowsSelected.png); border: 2px solid yellow}");
...但背景图像不会随焦点改变。
我也尝试过其他方法,使用 QPalette 等,但无法使它起作用。
有没有办法为小部件选择焦点样式?
...或者还有其他方法吗?
最佳答案
您不能直接在按钮上设置一个样式表,而在父部件上设置一个。按钮一将是首选。试试这个:
navButton->setStyleSheet("QPushButton { background-color:red; } QPushButton:focus { background-color:blue; }");
关于css - 如何在具有焦点时更改 QPushButton 图标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1531062/