开发者

in Qt Creator, How to set background image on QLabel of specific Class

I created a new class clickable label which inherits from QLabel and acts as a sort of "push button".

I would like to use background i开发者_如何学JAVAmages as the button it self. This way I could also change the background image for various states (disabled, clicked, released).

How can I either specify a style sheet to only change the attributes for that label, or change a property/attribute of Qlabel somehow? (I know the style sheet would be background-image url(xxx) but it would change all my buttons to that image in my custom class)

Thanks


You can target a specific widget by assigning a style sheet just to that particular widget by calling setStyleSheet(const QString & styleSheet) on it.

If you want to use a stylesheet further up the widget hierarcy, or at the application level, you can target a particular widget by using a css selector like this:

QWidget[objectName="myObject"]

You would need to make sure that the widget in question has its ojbect name set using setObjectName("myObject").

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜