焦点对准后如何更改QPushButton图标? [英] How to change a QPushButton icon when it has focus?

查看:60
本文介绍了焦点对准后如何更改QPushButton图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在S60 Qt应用程序中使用QPushButton.

I'm using a QPushButton in an S60 Qt app.

我希望按钮图标有焦点时可以更改.

I want the button icon to change when it has focus.

我已经尝试过了...

I've tried this...

navButton->setStyleSheet("background-image: url(c:/Data/navArrowsNotSelected.png);");
setStyleSheet("DoubleViewWidget QPushButton:focus {background-image: url(c:/Data/navArrowsSelected.png); border: 2px solid yellow}");

...但是背景图像不会随着焦点改变.

...but the background image doesn't change with focus.

我还尝试了其他方法,例如使用QPalette等,但无法使其正常工作.

I've also tried other approaches, using QPalette, etc., but can't get this to work.

是否可以为小部件选择焦点样式?

Is there a way to select a focus style for a widget?

...还是还有另一种方法?

...or is there another way to do this?

推荐答案

您不能直接在按钮上设置一个样式表,而在父窗口小部件上设置一个样式表.首选按钮一.试试这个:

You can't set one stylesheet directly on the button, and one on the parent widget. The button one will be prefered. Try this:

 navButton->setStyleSheet("QPushButton { background-color:red; } QPushButton:focus { background-color:blue; }");

这篇关于焦点对准后如何更改QPushButton图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆