css - 如何在具有焦点时更改 QPushButton 图标?

标签 css qt s60

我在 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/

相关文章:

c++ - 在 Qt 上使用 CMake 配置 VSCode - 找不到 ui_*.h 文件

c++ - Symbian C++ - 单个变量的持久存储

javascript - 为什么 Onload javascript 函数的运行速度比预期的要慢?

jquery - 不确定为什么这需要点击两次才能工作

qt - 在 TableView 中保持相同的选择颜色,无论它是否处于事件状态

java-me - 设备重启时自动启动 MIDlet?

c++ - Symbian C++ - 描述符上的子字符串操作

jquery - Margin Auto 渲染到 Margin 0px

css - 带有 drupal zen 主题和漂亮菜单的 Firefox 渲染问题

c++ - 无法启动状态以及状态之间的转换 : receiving various errors