在Qt Creator中,如何在特定类的QLabel上设置背景图像
我创建了一个新的可点击标签类,它继承自 QLabel 并充当一种 “按钮”。
我想使用背景图像作为按钮本身。这样我还可以更改各种状态的背景图像(禁用、单击、释放)。
如何指定样式表仅更改该标签的属性,或以某种方式更改 Qlabel 的属性/属性? (我知道样式表将是背景图像 url(xxx),但它会将我的所有按钮更改为自定义类中的该图像)
谢谢
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 images 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过调用 setStyleSheet(const QString & styleSheet) 为特定小部件分配样式表来定位特定小部件。
如果您想在小部件层次结构中进一步使用样式表,或者在应用程序级别,您可以使用 css 选择器来定位特定的小部件,如下所示:
您需要确保有问题的小部件的对象名称设置为使用
setObjectName("myObject")
。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:
You would need to make sure that the widget in question has its ojbect name set using
setObjectName("myObject")
.