使用QSS悬停父QFrame时如何设置子QLabels的颜色? [英] How to set color of child QLabels while hover parent QFrame with QSS?

查看:56
本文介绍了使用QSS悬停父QFrame时如何设置子QLabels的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用样式表在 QFrame 内设置 2 个标签的悬停状态颜色,但是无论是否存在实际悬停,框架都会采用悬停状态:

I'm trying to set the hover state color of 2 labels inside a QFrame with a stylesheet, but the frame takes the hover states regardless if there is an actual hover:

看截图:

我有一个带有 QLabels 的 QFrame.我将默认颜色设置为绿色和紫色.当我将鼠标悬停在 QFrame 上时,两个标签的颜色都应该变成红色.

I've got a QFrame with QLabels. I set the default colors to green and purple. While i hover the QFrame, the color of both labels should go red.

完全相同的 CSS 确实适用于 html,但我似乎无法理解它与 QT 样式表一起使用.

The exact same CSS does work with html, but i can't seem to get it to work with the QT stylesheets.

div{background-color:black; width:200px; height:100px;}

#label1{color: green;}
#label2{color: purple;}

div:hover #label1 {color: red;}
div:hover #label2 {color:red;}

推荐答案

QLabel 无法做到.这是QSS的限制.尝试使用 QToolButton 而不是 QLabel(并自定义 QToolButton 看起来像 QLabel).

You could not do it with QLabel. It's limitation of QSS. Try to use QToolButton instead of QLabel (and customize QToolButton to look like QLabel).

可能你也应该使用 QToolButton 而不是 QFrame.

Possible you shuld use QToolButton instead of QFrame too.

这篇关于使用QSS悬停父QFrame时如何设置子QLabels的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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